• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sybex Virtual Trainer errata?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic