A getB(){ return new A(); }
i don't get why this is false !
About Question enthuware.ocajp.i.v8.2.1145 :
Moderator: admin
-
- Posts: 1
- Joined: Fri Aug 03, 2018 8:42 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1145 :
Did you read the explanation? It explains exactly what is wrong with this code.
-
- Posts: 2
- Joined: Wed Aug 28, 2019 8:52 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1145 :
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!
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!
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1145 :
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.
-
- Posts: 2
- Joined: Wed Aug 28, 2019 8:52 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1145 :
Thank you for answering and not calling me an idiot lol
Who is online
Users browsing this forum: No registered users and 8 guests