What is differences between Overiding and Shadowing
Variables and Static methods are shadowing and instances method are overridden..??? how???
can some one explain little bit clearly
A Kumar
Ranch Hand
Joined: Jul 04, 2004
Posts: 973
posted
0
Hi,
Overriding means the instance methods in a parent class ...are redefined in the child class...
During the execution..which method should be executed depends upon the object...used in the call...
For static methods even if the child class has a method as the parent class ... You cannot call it as overridden...since the static methods are class level methods...
Static methods cannot be overridden..
If you consider the child class...We can say that the method in child hides the method in parent...
If you try to call these method...which one should be executed depends upon the type of reference than the object at runtime..
why static method looks on references and instance method looks on objects??
Akhilesh Trivedi
Ranch Hand
Joined: Jun 22, 2005
Posts: 1493
posted
0
Be the method static or not, but if the call is made in non-static context then I guess it is the reference that counts not the object for resolving which method to call.
I mean forget about the method type, whether it is static or non-static, but when you call a method using an instance variable (though static methods can be called using classes directly) it is always the reference that matters not the object. That is , you can have a child object in a parent reference. Using such a reference to access the method, would search called method in parent class only.