Page 1 of 1
About Question enthuware.ocajp.i.v8.2.1145 :
Posted: Sun Aug 05, 2018 5:50 am
by bsmboufous
A getB(){ return new A(); }
i don't get why this is false !
Re: About Question enthuware.ocajp.i.v8.2.1145 :
Posted: Sun Aug 05, 2018 6:04 am
by admin
Did you read the explanation? It explains exactly what is wrong with this code.
Re: About Question enthuware.ocajp.i.v8.2.1145 :
Posted: Wed Aug 28, 2019 8:58 pm
by MRamsey
I thought overridden methods had to be the same or less restrictive than the parent class's method. According to Liskov's Substitution Principle on this post:
https://stackoverflow.com/questions/161 ... n-base-cla
How is this answer correct if the method in class X is default accessible?
protected B getB(){ return new C(); }
Thank you for your help!
Re: About Question enthuware.ocajp.i.v8.2.1145 :
Posted: Wed Aug 28, 2019 10:43 pm
by admin
As the explanation says, protected is less restrictive than default. That is why it ok for the overriding method to be protected if the overridden method is with default access.
Re: About Question enthuware.ocajp.i.v8.2.1145 :
Posted: Thu Aug 29, 2019 7:57 am
by MRamsey

- I don't know what I was thinking...
Thank you for answering and not calling me an idiot lol