About Question enthuware.ocpjp.v11.2.3650 :

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

Moderator: admin

Post Reply
Dzholdoshev
Posts: 1
Joined: Tue Mar 21, 2023 3:28 pm
Contact:

About Question enthuware.ocpjp.v11.2.3650 :

Post by Dzholdoshev »

What if I want to print text from House's default method, what code should I write?
((House)off).lockTheGates(); doesn't work

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

Re: About Question enthuware.ocpjp.v11.2.3650 :

Post by admin »

You can call House.super.lockTheGates(); from within any instance method of HomeOffice class.

You cannot use this syntax from outside HomeOffice to invoke House's lockTheGates(), though. Meaning, if you have a reference to a HomeOffice object, then the method implemented by HomeOffice will be invoked. It is not possible to invoke the default method if the implementing object has overridden it.

It is the same as in any instance method in a super class - subclass hierarchy. Once a subclass overrides a superclass's method, it is not possible to access the super class's implementation. But that's ok because that's is the whole point of overriding a method.

giginar
Posts: 23
Joined: Fri Feb 07, 2025 5:36 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.3650 :

Post by giginar »

Even if you make HomeOffice abstract, it will still fail to compile because it will inherit two incompatible methods with the same name - one from Home, which is default and one from Office, which is abstract.

Hello, in this sentence there is a 'typo'; the name of the interface is not 'Home', it should be 'House'. thanks.

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

Re: About Question enthuware.ocpjp.v11.2.3650 :

Post by admin »

Noted. Thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 43 guests