A Java label-preview tool uses the following overloaded methods. Each returned width is measured in pixels. The Object overload assigns a fixed width, while the String overload uses the number of characters.
class LabelSizer { static int width(Object value) { return 12; } static int width(String value) { return 6 * value.length(); } static void preview() { String text = "CRATE"; Object stored = text; int storedWidth = width(stored); int textWidth = width(text); } }
When preview() runs, what values are assigned to storedWidth and textWidth? Give both widths in pixels as exact integers.
Unlock full course notes by signing up
Stages of overload resolution
When the Java compiler meets a call to a method name that has several overloads in a class, it follows a fixed procedure to decide which method the call invokes. Put the following stages of that procedure in the order the compiler carries them out.
Predicting the overload for six calls
A Java class declares exactly these four overloads of a static method f:
For each call in the table, type the parameter type of the overload the compiler selects: int, double, String or Object.
Value printed by a mixed overloaded expression
Consider the following Java program. The character 'A' has Unicode value 65.
What value does the program print? Give the number to one decimal place.
Diagnose competing two-parameter overloads
A delivery application's Java test helper returns a code identifying the selected overload. Weight arguments represent grams, and distance arguments represent kilometres. The returned codes are identifiers, not calculated charges.
Consider each table call independently inside a method of RouteProbe. Assume these are the only methods named route.
An ambiguous call has applicable overloads but no unique most-specific choice. Enter ambiguous for that outcome, no match when neither overload applies, or the exact returned integer when one overload is selected.