+ 4

we cannot override final method but can we do for static method how?

please help me with example

12th Mar 2017, 6:52 PM
Roshan Kumar
Roshan Kumar - avatar
2 Answers
+ 11
To call a static method you don't need to create an object of the method containing class. That's the answer itself - if you don't have an object, where will the method be overridden?
12th Mar 2017, 9:40 PM
Tashi N
Tashi N - avatar
0
[Question Extension] #more #info Then - extending the question - if I call the static method on the object (accepts it) then it is compiled as calling from the class? Example: class A { static void X() { /*A*/} } class B extends A { static void X() { /*B*/ } } code somewhere: { A a = new B(); a.X(); } So, a.X() runs like A.X() not caring about what the A variable contains (a B object)? ANSWER: I tested, and the A.X() runs :) TEST: https://code.sololearn.com/ch4Qfgmyjy9q
14th Apr 2017, 3:48 PM
Magyar DĂĄvid
Magyar DĂĄvid - avatar