Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Overriding Static Method....?

 
Manoj Mani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the follwing is true about static modifier.




A.static can be applied to : instance variables, methods,
code Segments and classes.

B.a static method cannot be overridden.

C.inner classes can be both static & private.

D.a static reference cannot be made through non static
method or code block.

E.abstract & static both can be applied together to a
method.



One of the answer is B.

How is it ? Check this program�����..No error nothing�Compiles and run..

class A
{
static void m()
{
System.out.println("In super class");
}
}

public class StaticOverride extends A
{
static void m()
{
System.out.println(" In Subclass");
}

public static void main(String args[])
{
StaticOverride ob = new StaticOverride();
m();
}
}
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hie Manoj,


Try to find out the difference between "Overriding and Redefining a method",
you will get your answer.

Tell me, don't you even think
"Static methods can't be overridden"


BTW: What are other correct answers you figure out?

Regards,
cmbhatt
[ April 11, 2007: Message edited by: Chandra Bhatt ]
 
Manoj Mani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C & D
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Overriding is an object-oriented feature and is connected with class families and polymorphism. Static members are theoretically outside the bounds of pure OO. Read up on this and you will see light!
 
wong sheena
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i believe you are looking for this

http://faq.javaranch.com/view?OverridingVsHiding
 
Arad Chear
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
answer is : A,B,C true
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack,

Please read the options carefully,

B,C are only the correct answers.

A is wrong!

Option D is confusing!



Please anybody make it clear!!!


cmbhatt
[ April 11, 2007: Message edited by: Chandra Bhatt ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The wording of option D is confusing.

If it means you can't call a static method from within a non-static method or code block, that is wrong.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic