This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Mock Exam Errata and the fly likes Sybex Virtual Trainer errata? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Sybex Virtual Trainer errata?" Watch "Sybex Virtual Trainer errata?" New topic
Author

Sybex Virtual Trainer errata?

Ulrich Rueth
Greenhorn

Joined: Feb 05, 2002
Posts: 3
There are two questions in the Sybex Virtual Trainer that in my view contradict each other. Or I might not have understood overriding...
Question 1:

What happens when you attempt to compile and run the following code?
1. class A { static void foo() {}; }
2. class B extends A { public static void foo() {}; }
Options:
a) Compiler error at line 1
b) Compiler error at line 2
c) No compiler error

Sybex says that c) -> A static method may only be overridden by another static method; that is what is done here, so the code compiles.
Question 2:

Which of the following is/are true?
A. A static method may be overridden by a static method.
B. ...

Sybex says that A is not true, because "static methods may not be overridden".
Now, may static methods be overridden or not?! I'm a bit confused...
Thanks for your help!
Ulrich
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
actually static methods are hidden (as the first question). Overriding applies to non-static methods.
There are a lot of divergences concerning the right terminology, but basically as per JLS overriding is for non-static methods and hiding for static methods...
So this is a good example of bad wording.
The first answer is correct but the explanation should be:
A static method may only be hidden by another static method; that is what is done here, so the code compiles.
The explanation of the second question is correct
Sybex says that A is not true, because "static methods may not be overridden".
So the problem lies in question 1.
HIH
[ February 06, 2002: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
 
subject: Sybex Virtual Trainer errata?
 
Similar Threads
overriding static methods
are static methods inherited
Static methods question
Certification Study Guide by Simon Roberts Philip Heller Micheal Ernst
True/False - Only non-static methods can be overridden