aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on overriding" Watch "Question on overriding" New topic
Author

Question on overriding

Diaz Thomas
Greenhorn

Joined: Sep 09, 2002
Posts: 8
Following is a question from JavaCaps Mock exam.
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.
The answer given is C.
But I think B is also right. A static method cannot be overridden by a non-static method. That implies B is right. Can someone clarify this for me.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Static methods can't be overridden, period. They can be hidden by static methods. This topic is being discussed in at least one other active thread in this forum.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Diaz Thomas
Greenhorn

Joined: Sep 09, 2002
Posts: 8
Thanks a lot Thomas. I remember reading that static methods cannot be overridden. But I was testing the following piece of code. Is this overriding of a static method? Forgive me if I am making a blunder.
class ClassA {
static void print() {
System.out.println("Class A");
}
}
public class ClassB extends ClassA {
public static void main(String args[]) {
ClassB b = new ClassB();
b.print();
}
static void print() {
System.out.println("Class B");
}
}
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
No. That is hiding.
Overriding implies polymorphism and static methods don't participate in polymorphism because they are inlined at compile time.
Diaz Thomas
Greenhorn

Joined: Sep 09, 2002
Posts: 8
Thanks. But I am bit
Jim Crawford
Ranch Hand

Joined: Sep 08, 2002
Posts: 127
Read through this as well... Maybe you'll understand better.
http://www.coderanch.com/t/239320/java-programmer-SCJP/certification/Overriding-hiding-methods


<img src="cool.gif" border="0"> <img src="graemlins/beerchug.gif" border="0" alt="[beerchug]" /> <br />SCJP 1.4
Diaz Thomas
Greenhorn

Joined: Sep 09, 2002
Posts: 8
That helped a lot Jim. I feel more confident now.
Thanks
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Hi Diaz, here's another example:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Question on overriding