• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Sybex Virtual Trainer errata?  RSS feed

 
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
 
Gold Digger
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 ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!