Java OCA OCP Practice Question 1319

Question

Given the following method and the fact that FileNotFoundException is a subclass of IOException, which of the following method signatures is a valid override by a subclass?

protected void m() throws FileNotFoundException {} 

A.   void m() throws IOException 
B.   public void m() throws IOException 
C.   private void m() throws FileNotFoundException 
D.   public final void m() 



    D.

    Note

    Options A and C are incorrect because an overridden method cannot reduce the visibility of the inherited method.

    Option B is incorrect because an overridden method cannot declare a broader checked exception than the inherited method.

    Option D is the correct answer.

    The removal of the checked exception, the application of a broader access modifier, and the addition of the final attribute are allowed for overridden methods.




    PreviousNext

    Related