• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Moc Qes on Static var ,chap 2.

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is ques 11 in selftest of chap 2 ,K&B.
Class Uber
{ static int y;...}

class Minor extends Uber //inherits static var
{
Minor()
{ super(y); //changes variable
y=y+3; ///use/modifies of static var}
...}

Now Minor classs also having its own static int y;
when it calls super(y),super class Uber modifies ..it.Shouldnt Uber class
change its own static variable
Uber(int x)
{
this ();
y =y*2;} //here and next line ,y modified ..it should be of class Uber.
Uber(){y++;}

How come Minor class's y is modified.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way you're asking the question makes it a little bit unclear what you mean exactly.

Class Minor does not have its own copy of the static member variable y in class Uber.
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic