About Question enthuware.ocpjp.ii.v11.2.3510 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
JanisK
Posts: 3
Joined: Mon Sep 16, 2019 1:37 am
Contact:

About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by JanisK »

There's some inaccuracy in explanation of one of the answers:
You cannot override a static method with a non-static method. You can, however, redeclare a static method of a super interface as a default method in the sub interface.
First part contradicts second part. I believe in first sentence "static" and "non-static" should be switched places.

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

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by admin »

Why do you think it is contradictory? They are two different things. static methods cannot be overridden.
Declaring static method of a super interface as a default method in the sub interface is not overriding.

Yes, the reverse i.e. "static method cannot override a non-static method" is also true.

Will improve the explanation to make it clear.
thank you for your feedback!

JanisK
Posts: 3
Joined: Mon Sep 16, 2019 1:37 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by JanisK »

Thank you for clarification, I see now, that there are no contradictions.
If I give it one more thought than I can see

But the switching part is still in question.
Static methods cannot be overriden at all and in that case "with a non-static method" part only confuses. While IMO
You cannot override non-static method with a static method
makes much more sense and fits more with the answer option provided.

AngelVzla
Posts: 1
Joined: Sat Jul 04, 2020 7:17 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by AngelVzla »

I second this, have to re-read it a couple of times to finally understand the idea behind it.
It's not that hard, its just that is simpler to have something as mentioned
You cannot override non-static method with a static method

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

Re: About Question enthuware.ocpjp.ii.v11.2.3510 :

Post by admin »

I see that it is already mentioned under option 1:
You cannot override a non-static method with a static method and vice versa. You can, however, redeclare a static method of a super interface as a default method in the sub interface.
An example has now been added to make it clearer:

Code: Select all

class Base{
  static void m(){ }
  void n(){ }
  static void x(){ }
  void y(){ }
}
class Sub extends Base{
  void m(){ } //WILL NOT COMPILE
  static void n(){ } //WILL NOT COMPILE
  static void x(){ } //VALID, x() of base is hidden
  void y(){ } //VALID, y() of base is overridden
}

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests