OCP Oracle Certified Professional Java SE 11 Programmer I Exam Fundamentals 1Z0-815: Study guide for passing the OCP Java 11 Developer Certification Part 1 Exam 1Z0-815 (p. 5). Enthuware. Kindle Edition.
"For example, an overriding method cannot throw a more generic exception that the one declared by the overridden method. On the other hand the constructor of a subclass cannot throw only a more specific exception than the one thrown by the constructor of the superclass. Think about that."
The word "only" need to be removed. I think the text meant to say
" On the other hand the constructor of a subclass cannot throw a more specific exception than the one thrown by the constructor of the superclass. Think about that."
Errata : OCP Oracle Certified Professional Java SE 11 Programmer I Exam Fundamentals 1Z0-815 - Kindle edition
Moderator: admin
-
- Posts: 21
- Joined: Mon Sep 30, 2019 9:48 pm
- Contact:
-
- Site Admin
- Posts: 10404
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: Errata : OCP Oracle Certified Professional Java SE 11 Programmer I Exam Fundamentals 1Z0-815 - Kindle edition
No, the statement is correct. "only" is intended. Observe the following code:
Code: Select all
class X{
public X() throws IOException{
}
}
class Y1 extends X{
public Y1() throws Exception{ //works
}
}
class Y2 extends X{
public Y2() throws FileNotFoundException, IOException{ //works
}
}
class Y3 extends X{
public Y3() throws FileNotFoundException{ //DOES NOT WORK
}
}
-
- Posts: 21
- Joined: Mon Sep 30, 2019 9:48 pm
- Contact:
Re: Errata : OCP Oracle Certified Professional Java SE 11 Programmer I Exam Fundamentals 1Z0-815 - Kindle edition
ok got it . So you mean to say it cannot just throw a more specific exception . It can however throw a more specific exception as long as it also throws the more generic exception declared in the parent class.
Thank you for the clarification.
Thank you for the clarification.
Who is online
Users browsing this forum: Bing [Bot] and 18 guests