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.


Java
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.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Method Overloading Questions: