Java OCA OCP Practice Question 30

Question

Suppose class X contains the following method:

void doSomething(int a, float b)  { ... } 

Which of the following methods may appear in class Y, which extends X?

A.  public void doSomething(int a, float b) { ... } 
B.  private void doSomething(int a, float b) { ... } 
C.  public void doSomething(int a, float b) throws java.io.IOException { ... } 
D.  private void doSomething(int a, float b) throws java.io.IOException { ... } 


A.

Note

A method with default access may be overridden to have default, protected, or public access but not private access, because a method may not be overridden with more restrictive access.

An overriding method may not declare that it throws exception types that do not appear in the superclass version.




PreviousNext

Related