Question 17) Which of the following statements are true?
1) static methods do not have access to the implicit variable called this 2) a static method may not be overriden 3) a static method may not be overriden to be non-static 4) a static method may not be overloaded
Answer given is 1 and 3. according to me 2 is also the answer.It is hidden and not overriden What say???
Rajani
anwar_a
Greenhorn
Joined: Aug 21, 2000
Posts: 7
posted
0
Static method can very well be overriden. So 2 is wrong Regards Anwar ------------------
Rajani Deshpande
Ranch Hand
Joined: May 08, 2000
Posts: 45
posted
0
No Anwar, They can never be over ridden. you can hide them by defining the same method in a subclass. but u can always access them using the class name. So it is proper to say static methods are hidden and improper to say they are overridden.
sath
Greenhorn
Joined: Aug 24, 2000
Posts: 5
posted
0
My understanding is that static methods are implicitly final. So, there is no question of overriding a static method. well, what do other's say about this?? -sath
Biju Narayanan
Greenhorn
Joined: Aug 25, 2000
Posts: 4
posted
0
A parent class and a child class can have static funcions with same signature and return type. This means static methods can be overridden. So if you call a static method of a class and the method is not in that class, it tries to find a funcion with the same signature up in the class hierarchy. But there is a slight problem when you use objects to call static fucntions. Think of this situation. A static method amethod() in class A is overridden in sub class B. You create an object of B and assign it to an object variable of A. Now you call the static method using A.amethod(). It picks up the amethod() of the parent, not of the child. If amethod() were non static, it would have picked up the amethod() of B. The reason is static methods are resolved at compilation and compiler honours the type of object variable.