First part contradicts second part. I believe in first sentence "static" and "non-static" should be switched places.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.
About Question enthuware.ocpjp.ii.v11.2.3510 :
Moderators: Site Manager, fjwalraven
-
- Posts: 3
- Joined: Mon Sep 16, 2019 1:37 am
- Contact:
About Question enthuware.ocpjp.ii.v11.2.3510 :
There's some inaccuracy in explanation of one of the answers:
-
- Site Admin
- Posts: 10322
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3510 :
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!
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!
If you like our products and services, please help us by posting your review here.
-
- Posts: 3
- Joined: Mon Sep 16, 2019 1:37 am
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3510 :
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
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
makes much more sense and fits more with the answer option provided.You cannot override non-static method with a static method
-
- Posts: 1
- Joined: Sat Jul 04, 2020 7:17 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3510 :
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
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
-
- Site Admin
- Posts: 10322
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3510 :
I see that it is already mentioned under option 1:
An example has now been added to make it clearer: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.
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
}
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 6 guests