class sup { static void method(){System.out.println("Super");} // 1 }
class test extends sup { public static void main(String args[]) {} static void method(){System.out.println("test");} }
Is this an example of overriding? I thought static methods cannot be overridden...they can only be hidden... This concept is not clear to me. Can someone help me understand this?
Thanks!
vijaya saradhi
Ranch Hand
Joined: Dec 31, 2007
Posts: 32
posted
0
Hi Divya.
First of all static methods belong to class.And they are not per each and evry object, ie not per instance of a class.So overriding can be done only on non static member functions (instance methods only).
Since static members are part of a class nt seperate for each and evry individual objects of a class, this overriding concept doesn't apply to them.
even though static methods are inherited, they cannt be invoked dynamically using parent class reference(ie no dynamic binding since static)
for eg: note even though the object is of type B the static function of the type A (base) is called