Object Superclass

AP Computer Science A· difficulty 3/5

public class P { int x; public P(int x) { this.x = x; } }
P a = new P(1);
System.out.println(a);

What is printed?

  • A

    Something like P@1a2b3c (hash code form)

    check_circle
  • B

    1

  • C

    Compile-time error

  • D

    P

Explanation

Without toString override, Object.toString returns "ClassName@hex".

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

Related questions