+ 2
It it possible to override static methods in Java?
https://code.sololearn.com/c5qiFCG71pXY/?ref=app It is work. Why not?
6 Respuestas
+ 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)