• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Marcus exam 3 q 17

 
Rajani Deshpande
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???
 
anwar_a
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static method can very well be overriden. So 2 is wrong
Regards
Anwar
------------------
 
Rajani Deshpande
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic