A static method cannot be overriden it can only be hided. It doesnt involve in polymorphic behaviours since it belongs to a class and not to an instance.
hi srini, ya static methods cannot be overridden. i.e if we have static methoids in the super as well as the child class always the super class static method is executed,even if we call thru an instance of the child class .And they call this hiding ... how ya??can u explain.. my question may be silly ,but if possible tel me wats hiding here
Harish<br />SCJP 1.4 (85%)
Srinivasa Raghavan
Ranch Hand
Joined: Sep 28, 2004
Posts: 1228
posted
0
how ya??can u explain..
Harish Please take care to post in proper english , it's good to avoid SMS language like 'u' , 'r' etc
Now comming to your question, The static method in the subclass shadows the static method in the superclass. Static are figured out compile time and instance method are figured out at run time.
Is it true that static method can override another override method only through inheritance?
or can static method overload another static method
Srinivasa Raghavan
Ranch Hand
Joined: Sep 28, 2004
Posts: 1228
posted
0
if we have static methoids in the super as well as the child class always the super class static method is executed,even if we call thru an instance of the child class .
Harish, First of all the code mentioned above wont compile as you are returning void from the method & using it in System.out.println(..) See the static method in the super class wont execute always , Call the static method without type casting it to Sure Class.
harish shankarnarayan
Ranch Hand
Joined: Sep 12, 2005
Posts: 158
posted
0
Static are figured out compile time and instance method are figured out at run time. thats wat canu explain this with an example sorry shall not use SMS language frm now
Srinivasa Raghavan
Ranch Hand
Joined: Sep 28, 2004
Posts: 1228
posted
0
thats wat canu explain this with an example sorry shall not use SMS language frm now
Thats great but again you used it there
As i said in my previous reply ( sorry for the typo there ) Try to call the Static method withou type casting it to Super Class like t.m2() and now try to cast it and call the Static method.
The code given by in Naresh Saw beggining is not complining in JDK1.4 Got the error message as ---------- Javac ---------- test1.java:28: inconvertible types found : void required: Super System.out.println((Super)t.m1()); // 1 ^ test1.java:29: inconvertible types found : void required: Super System.out.println((Super)t.m2()); // 1 ^ 2 errors -------------------------------------------------------
Please explain me clearly about this .
ALso tell me whether static method can be overloaded or not