• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Doubt in K&B SCJP 5: Chap 2, SELF TEST, Q 11

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Please refer to the 11th Question in Self Test of Chapter 2:


Shouldn't the Answer be 'Compilation Error', as 'y' is a static variable and hence wont be inherited in the 'Minor' class which is using it in the default constructor?
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kunal dabir:
Hi,

Please refer to the 11th Question in Self Test of Chapter 2:


Shouldn't the Answer be 'Compilation Error', as 'y' is a static variable and hence wont be inherited in the 'Minor' class which is using it in the default constructor?




[ September 08, 2008: Message edited by: Samus Aran ]
 
kunal dabir
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Sam for your kind reply. I am sorry for missing the 'extends Uber'. If it missed 'extends', it would not anyhow work.

What i used to think was, static members declared in parent class cant be referred from child class. thats why i got confused. After reading your reply, i wrote this

which prints 3 twice. It shows that x is still only in Parent, while Child updates Parent's copy.

Thanks again.
 
Climb the rope! CLIMB THE ROPE! You too tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic