• 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

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic