Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.791 and enthuware.ocajp.i.v7.2.1167 :

Posted: Sun Nov 02, 2014 7:39 pm
by ssack2014
Why is B's m() not an override of A's m()? or am I looking at this question wrong?

Re: About Question com.enthuware.ets.scjp.v6.2.791 :

Posted: Sun Nov 02, 2014 7:42 pm
by ssack2014
the modifier is less restrictive.


//in file A.java
public class A
{
protected void m() throws SomeException{}
}

//in file B.java
public class B extends A
{
public void m(){ }
}

Re: About Question com.enthuware.ets.scjp.v6.2.791 :

Posted: Sun Nov 02, 2014 9:59 pm
by admin
It is a valid override. The explanation doesn't say that it is not a valid override either. So I am not sure what is the problem?

-Paul.

Re: About Question com.enthuware.ets.scjp.v6.2.791 :

Posted: Sat Feb 18, 2023 3:18 pm
by edufin166@yahoo.com
Ok.

As I could see. We have 2 correct answers:

A a = new B();
a.m();


A a = new B();
( ( B) a ).m();

Am I right?

Re: About Question com.enthuware.ets.scjp.v6.2.791 and enthuware.ocajp.i.v7.2.1167 :

Posted: Sat Feb 18, 2023 11:35 pm
by admin
A a = new B();
a.m();
Did you read the explanation provided for this option? It explains exactly why this option is not correct.
A's m() declares 'throws SomeException', which is a checked exception, while the main() method doesn't. So a.m() must be wrapped in a try/catch block.