Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Overriding Static Method....? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in Overriding Static Method....?" Watch "Doubt in Overriding Static Method....?" New topic
Author

Doubt in Overriding Static Method....?

Manoj Mani
Ranch Hand

Joined: Mar 31, 2007
Posts: 65
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();
}
}


Impossible Is Often Untried.Its Time For Us To Change....
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
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 ]

cmbhatt
Manoj Mani
Ranch Hand

Joined: Mar 31, 2007
Posts: 65
C & D
Stuart Ash
Ranch Hand

Joined: Oct 07, 2005
Posts: 637
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!


ASCII silly question, Get a silly ANSI.
wong sheena
Greenhorn

Joined: Apr 07, 2007
Posts: 23
i believe you are looking for this

http://faq.javaranch.com/view?OverridingVsHiding
Arad Chear
Ranch Hand

Joined: Jan 05, 2007
Posts: 98
answer is : A,B,C true
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
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

Joined: Feb 07, 2005
Posts: 2367
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in Overriding Static Method....?