• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sybex Virtual Trainer errata?

 
Ulrich Rueth
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic