Page 1 of 1

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

Posted: Mon Sep 16, 2019 1:46 am
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.

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

Posted: Mon Sep 16, 2019 4:11 am
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!

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

Posted: Mon Sep 16, 2019 5:34 am
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.

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

Posted: Sun Jul 12, 2020 11:46 pm
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

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

Posted: Mon Jul 13, 2020 12:29 am
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
}