• Post Reply Bookmark Topic Watch Topic
  • New Topic

super class static variable  RSS feed

 
Vikas J Yadav
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does the super class static variable behaves in child class?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vikas J Yadav wrote:How does the super class static variable behaves in child class?

Erm, sorry. Don't understand the question.

It works the same as any other variable; ie, its "behaviour" (not sure that that's the right word, BTW) will be determined by its visibility (public, protected, private, etc).

Oh, and static variables are almost always a bad thing, so I'd avoid them like the plague.

Winston
 
Vikas J Yadav
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me be specific, is this static variable inherited in the subclass or it is shared with the subclass?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vikas J Yadav wrote:Let me be specific, is this static variable inherited in the subclass or it is shared with the subclass?

Neither. Anything static belongs to the class, not an instance of it, so inheritance doesn't apply. As to "sharing", again, I'm not sure what you mean. If you mean "is is visible?" or "can I use it?", then read what I said above.

Some confusion can arise because static variables can be referred to via an instance - a very bad habit to get into, BTW - and in that case, if a parent and child both define the same static variable, the child's one will mask (or 'hide') the parent's. However, there's no inheritance involved, and the child version can even be a different type.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!