Object Superclass

AP Computer Science A· difficulty 3/5

public class Plain {
    private int x = 5;
}
// ...
Plain p = new Plain();
String s = p.toString();
System.out.println(s.startsWith("Plain@"));

What is printed?

  • A

    Plain@5

  • B

    Compile-time error

  • C

    true

    check_circle
  • D

    false

Explanation

Without overriding, Object's toString returns the form ClassName@hash, so the string starts with "Plain@".

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

Related questions

AP Computer Science A · Object Superclass Practice Question | Acemy