Java OCA OCP Practice Question 798

Question

Which of the following method definitions will prevent overriding of that method?

Select 4 options

  • A. public final void m1 ()
  • B. public static void m1 ()
  • C. public static final void m1 ()
  • D. public abstract void m1 ()
  • E. private void m1 ()


Correct Options are  : A B C E

Note

For Option A. public final void m1 ()

final methods cannot be overridden. That is the purpose of final keyword.

For Option C. public static final void m1 ()

Keep in mind that static methods are not overridden, they are shadowed.

For Option E. private void m1 ()

private methods are not inherited at all so there is no question of overriding a private method.




PreviousNext

Related