About Question enthuware.ocajp.i.v8.2.1145 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
bsmboufous
Posts: 1
Joined: Fri Aug 03, 2018 8:42 am
Contact:

About Question enthuware.ocajp.i.v8.2.1145 :

Post by bsmboufous »

A getB(){ return new A(); }

i don't get why this is false !

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1145 :

Post by admin »

Did you read the explanation? It explains exactly what is wrong with this code.
If you like our products and services, please help us by posting your review here.

MRamsey
Posts: 2
Joined: Wed Aug 28, 2019 8:52 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1145 :

Post 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!

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1145 :

Post 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.
If you like our products and services, please help us by posting your review here.

MRamsey
Posts: 2
Joined: Wed Aug 28, 2019 8:52 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1145 :

Post by MRamsey »

šŸ¤¦ - I don't know what I was thinking...

Thank you for answering and not calling me an idiot lol

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 38 guests