Consider the following Java program. The character 'A' has Unicode value 65.
public class Scaler { static int scale(int x) { return x * 2; } static long scale(long x) { return x + 100; } static double scale(double x) { return x / 2; } public static void main(String[] args) { double r = scale(4) + scale(4L) + scale(9.0) + scale('A'); System.out.println(r); } }
What value does the program print? Give the number to one decimal place.
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.
One label object, two selected overloads
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.
When preview() runs, what values are assigned to storedWidth and textWidth? Give both widths in pixels as exact integers.
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.