+ 2
It it possible to override static methods in Java?
https://code.sololearn.com/c5qiFCG71pXY/?ref=app It is work. Why not?
6 Answers
+ 9
Eleonora Lyonesse In Java, we can declare aĀ static methodĀ in the child class with the same signatures as in Parent class. But it will not be considered theĀ method overriding. TheĀ static methodĀ of child class will hide the implementation of the method of Parent class. It is known asĀ methodĀ hiding. Because the compiler decides which method to execute at the compile-time, not at the runtime. As you know the static method can be accessed by class name rather than the object. When the compiler invokes the static method then it accesses theĀ static methodĀ of the child class.
For more details with example: https://javagoal.com/can-we-override-the-static-method-in-java/
+ 8
Eleonora Lyonesse
Apparently in your example that is called Method Hiding and not method overriding.
Take a look š
https://www.tutorialspoint.com/What-is-method-hiding-in-Java-and-how-to-use-it#:~:text=Java%208Object%20Oriented%20Programming,is%20known%20as%20method%20hiding.
Static methods can't be overridden.
Please check these posts tooš
https://www.sololearn.com/post/225388/?ref=app
https://www.sololearn.com/post/225380/?ref=app
Credit : PāWAN MāURYā š
+ 6
You can't.
https://www.sololearn.com/learn/Java/2165/
+ 2
https://www.sololearn.com/post/634447/?ref=app
+ 2
ok, thanks!!!)
+ 2
I think, Ulyana Sveleba confused overloading and overriding in the questions (SoloLearn challenges)