+ 2

Can you override a private or static method in Java ?

10th May 2017, 5:10 PM
Nikhil
Nikhil - avatar
2 Respuestas
+ 18
No, a private method cannot beoverridden since it is not visible from any other class. You have declared a new method for your subclass that has no relation to the superclass method. One way to look at it is to ask yourself whether it would be legal to write super.func() in the Derived class. Static methods cannot be overridden because they are not dispatched on the object instance at runtime. The compiler decides which method gets called. ... No,Static methods can't be overriden as it is part of a class rather than an object. But one can overloadstatic method. :-D
10th May 2017, 5:14 PM
Dev
Dev - avatar
+ 4
out of topic : @Dayve I'm super exciting , can't wait to see you reaching Level 16 with platinum !!
10th May 2017, 9:08 PM
Abdel
Abdel - avatar