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

Question 50

Consider the following code:

What is the result ?

  • A

    Test class method

  • B

    Compilation Fails.

  • C

    interface default method

  • D

    An exception is thrown at runtime.

Reveal correct answer

Correct answer: B

Explanation

We can declare methods with default keyword only in interface but not in class. Hence we will get compile time error.
Test.java:10: error: modifier default not allowed here
default void m1()

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