Oracle Certified Associate Java Se 8 Programmer · Free Practice Question Easy

Question 53

What will be the result of compiling and executing Test class?

  • A

    Compilation error

  • B

    None of the other options

  • C

    NullPointerException is thrown

  • D

    static method

Reveal correct answer

Correct answer: D

Explanation

print() is static method of class Test. So correct syntax to call method print() is Test.print();

but static methods can also be invoked using reference variable: obj.print(); Warning is displayed in this case.

Even though obj has null value, we don't get NullPointerException as objects are not needed to call static methods.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need