• 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
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

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.
reply
    Bookmark Topic Watch Topic
  • New Topic