Page 1 of 1
About Question enthuware.ocpjp.v8.2.1823 :
Posted: Mon Mar 26, 2018 1:26 am
by Sergey
If we cannot override the final method (mA), how is it possible to call it from TestClass?
Re: About Question enthuware.ocpjp.v8.2.1823 :
Posted: Mon Mar 26, 2018 4:40 am
by admin
Why do you think final has anything to do with access?
Re: About Question enthuware.ocpjp.v8.2.1823 :
Posted: Mon Mar 26, 2018 5:06 am
by Sergey
We instantiate object of Encyclopedia:
Code: Select all
Book o1 = new Encyclopedia (); //3
After we want to 'execute' method:
But since type of reference is Book, we need that class Book has mA method. It really has it. But we must `execute` this method from Encyclopedia object, and since this method (in Encyclopedia object) is not compile, how could we `execute` it?
Re: About Question enthuware.ocpjp.v8.2.1823 :
Posted: Mon Mar 26, 2018 5:45 am
by admin
Sorry but I am not sure what you mean by "and since this method (in Encyclopedia object) is not compile". Can you be a bit more clear about what you mean by this so that I can address your confusion?
Remember that final just means that a subclass cannot override it. It doesn't mean the subclass cannot access it or can not inherit it. This is OCAJP stuff

Re: About Question enthuware.ocpjp.v8.2.1823 :
Posted: Mon Mar 26, 2018 6:15 am
by Sergey
I just try to understand if the line //2 will cause compilation to fail, then how could we run method o1.mA()? Since this method is fail to compile. By this logic the line //4 should not compile too?
I have passed OCA (81%)

))
Re: About Question enthuware.ocpjp.v8.2.1823 :
Posted: Mon Mar 26, 2018 6:19 am
by Sergey
In other words, how could we run something if this "someting" is not compiled?
Re: About Question enthuware.ocpjp.v8.2.1823 :
Posted: Mon Mar 26, 2018 1:10 pm
by admin
Sergey wrote:In other words, how could we run something if this "someting" is not compiled?
Line marked //2 doesn't compile because it is trying to override a final method. There is no problem with line marked //4 because Encylopedia inherits method mA() from Book.
Re: About Question enthuware.ocpjp.v8.2.1823 :
Posted: Tue Mar 27, 2018 12:46 am
by Sergey
Thanks. Now it is clear. It (method mA()) cannot be overridden but it inherited.