Page 1 of 1

About Question enthuware.ocpjp.v11.2.3650 :

Posted: Wed Mar 22, 2023 11:54 pm
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

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

Posted: Thu Mar 23, 2023 8:30 am
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.