Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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

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.
 
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic