Possible incorrect answer in exam bank

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
angersleek
Posts: 1
Joined: Thu Nov 26, 2020 3:26 pm
Contact:

Possible incorrect answer in exam bank

Post by angersleek »

This is about question 52 in Foundation Test 3 no: 52

Q: Which of the following statements are true?

The following is NOT correct based on the test.
An overriding method can declare that it throws a wider spectrum of checked exceptions than the method it is overriding.

But isn't this correct?

The following example showcases this. Where the overriding method is in fact throwing a wider spectrum of checked exceptions and compiles fine.
Am I missing something, misread the question / answer? Please advice. Thank you.

Code: Select all

import java.io.IOException;

public class App extends Haha {

    @Override
    void test() throws IOException, InterruptedException, NoSuchMethodException, IllegalAccessException {

    }
}

class Haha {

    void test() throws Exception {

    }
}

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Possible incorrect answer in exam bank

Post by admin »

IOException and InterruptedException are subclasses of Exception. So, it is not wider but narrower list of exceptions.
Wider means super class, narrower means sub class.
This is explained nicely in section 11.4.1 Overriding methods of Hanumant Deshmukh's OCAJP 8 Fundamentals book.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests