Page 1 of 1

Errata : OCP Oracle Certified Professional Java SE 11 Programmer I Exam Fundamentals 1Z0-815 - Kindle edition

Posted: Wed Oct 02, 2019 7:22 pm
by nk2164
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."

Re: Errata : OCP Oracle Certified Professional Java SE 11 Programmer I Exam Fundamentals 1Z0-815 - Kindle edition

Posted: Wed Oct 02, 2019 11:35 pm
by admin
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
  }

}

Re: Errata : OCP Oracle Certified Professional Java SE 11 Programmer I Exam Fundamentals 1Z0-815 - Kindle edition

Posted: Thu Oct 03, 2019 1:05 am
by nk2164
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.