Can we override private or static method in java? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 3

Can we override private or static method in java?

Method Overriding in which have method got same name & same parameters...

20th Feb 2018, 3:23 PM
Ajay Verma
Ajay Verma - avatar
2 Respostas
+ 14
Static methodsĀ also cannot beĀ overridden, becauseĀ static methodsĀ are a part of the Class itself, and not a part of any instance(object) of that class.Ā YouĀ howeverĀ canĀ declare samestatic methodĀ with same signature in child classes, but that would not be considered as runtime polymorphism (overrideĀ ofmethods) . https://www.geeksforgeeks.org/can-we-overload-or-override-static-methods-in-java/ https://www.geeksforgeeks.org/can-override-private-methods-java/ https://www.sololearn.com/learn/Java/2165/?ref=app
20th Feb 2018, 3:34 PM
Abhivarshini Maddala
Abhivarshini Maddala - avatar
+ 2
private methods arent visible to subclasses so no. overriding statics makes no sense because you need to specify the class by calling them which destroys the purpose.
20th Feb 2018, 3:35 PM
Jeremy
Jeremy - avatar