About Question enthuware.ocpjp.v8.2.1829 :

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

Moderator: admin

Post Reply
Online
admin
Site Admin
Posts: 10061
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1829 :

Post by admin »

lenalena wrote: a child interface can override a static method with default
Please read my post above again. The word "override" is not applicable in this situation but yes, it can have a method with the same signature. This is not a case of "override" though.
lenalena wrote: but NOT default method with static..
Correct.

You need to understand that the word "override" has a specific meaning in Java and OOP (google). Merely having a method with the same signature in parent and sub class/interface does not necessarily involve "overriding".
lenalena wrote: And a child interface cannot access parent's static methods.
It can; using the name of the parent class/interface. If I2 extends I1, you can call I1.staticMethod(); from inside I2. But you cannot invoke it directly without the name (unlike in case of a class, where you can).
lenalena wrote: a child class does not "override" static methods because it doesn't technically inherit it, but can access it's ancestors' static methods.
Correct.
lenalena wrote: A class cannot override an inherited (from an interface) default method with a static.
Correct.

You should try out some test programs to verify and to make sure you remember the rules. There are questions in the exam on this type of thing.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

lenalena
Posts: 56
Joined: Tue Feb 21, 2017 4:24 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1829 :

Post by lenalena »

Thanks, Paul,

I did write test programs, and I'm just trying to generalize and confirm what they showed.

Thank you for taking the time to go through it.

Also, a class cannot invoke the implemented interface's static method directly, has to call it through interface's name. So it's not about who does the calling, it's about who declares the static method. Interface's static methods cannot be accessed directly, while a class' can...

On the side note, is there a logical reason why a class' static method can be accessed by children while an interface's cannot? Is it because there is no implied "super" reference to an implemented/extended interface?

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

Re: About Question enthuware.ocpjp.v8.2.1829 :

Post by admin »

lenalena wrote: On the side note, is there a logical reason why a class' static method can be accessed by children while an interface's cannot? Is it because there is no implied "super" reference to an implemented/extended interface?
I haven't come across any valid reason for why a class' static method can be accessed by children directly. It should not have been able to and is a design flaw in the language, IMHO. I just made this argument here: https://coderanch.com/t/680085/certific ... ce#3189912

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: admin and 118 guests