Writing Methods

AP Computer Science A· difficulty 3/5

public class K {
    public void f(int x) { System.out.print("int "); }
    public void f(Object x) { System.out.print("obj "); }
}
// ...
K k = new K();
k.f(7);
k.f("a");

What is printed?

  • A

    obj obj

  • B

    int obj

    check_circle
  • C

    int int

  • D

    obj int

Explanation

7 matches f(int) exactly; "a" is a String which is an Object, matching f(Object).

Want 10 more like this — adaptive to your weak spots?

Related questions