Static Variables and Methods

AP Computer Science A· difficulty 4/5

Calling a static method on an instance reference (<code>obj.staticMethod()</code>)

  • A

    Polymorphically dispatches based on obj's runtime type

  • B

    Compiles and runs, but the method does not bind to obj — only the class

    check_circle
  • C

    Causes a compile error

  • D

    Throws NullPointerException at runtime

Explanation

Java permits invocation through an instance but warns it. Static binding is by the declared type's class, not the runtime object, and <code>this</code> is unavailable.

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

Related questions