Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaCaps mock 1 Q:39

 
Haining Mu
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
39. Which of the following statements are true?
A) An inner class cannot be defined as private.
B) Static methods can be overridden by static methods only.
C) Static variables can be called using class name.
D) Non static variables can be called using class name.
Answer:BC
For B, are we saying static method can NOT be overridden. They are just happen to have the same return type, method name, para list if we see two static methods in two classes, right?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The rule is that static methods can not be overridden to be non-static.
 
Haining Mu
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Thomas Paul:
The rule is that static methods can not be overridden to be non-static.

not quite get it. Mughal's book p181 says 'Any final, static and private methods in a class cannot be overridden'. And in JLS 8.4.6, for static method, it is called 'hiding' not overriding respect to instance method. What we do it havaing such a problem in SCJP exam?
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haining,
There's a good chance you won't see a question with similar wording on the real exam. The exam is based on the rules in the JLS; not partial or misleading information.
[This message has been edited by Jane Griscti (edited June 17, 2001).]
 
junaid rehman
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the answer of the first answer is correct or not
can any pls explain more
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Juanid,
'static' methods belong to the class. Overriding involves 'objects' or 'instances' of a class so technically a 'static' method cannot be overidden although a static sub-class method may 'hide' a superclasses static method.
See the Sun Tech Tip Shadowing
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited June 17, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic