Skip to main content
gamedev.net
🔒 Locked

Inheritance Question

Started by falkone Apr 23, 2003 at 8:39 AM 2 replies 650+ views
Original Post
falkone
falkone
I have a question.. i asked my programming teacher but she either didn''t seem to understand or didn''t know. say i have a class.. and in this class, i have a static variable ''var''. Through all instances of this class, ''var'' will act as only one variable, having the same value in all classes, correct? Now, if i inherit another class from the first class, will this new class share the same static variable ''var''? or will it have a new static variable ''var'' shared with only data of type of the new class? Thanks Falkone
Disclaimer: "I am in no way qualified to present advice n any topic concerning anything and can not be held responsible for any damages that my advice may incurr (due to neither my negligence nor yours)" o
Oluseyi
Oluseyi
quote:
Original post by falkone
say i have a class.. and in this class, i have a static variable ''var''. Through all instances of this class, ''var'' will act as only one variable, having the same value in all classes, correct? Now, if i inherit another class from the first class, will this new class share the same static variable ''var''? or will it have a new static variable ''var'' shared with only data of type of the new class?

If the variable is inheritable (public or protected), then it will be the same for the derived class.
MARS_999
MARS_999
To clear it up, if the variable is declared static and is public or protected the variable will be inherited as static to the derived class. This means that the derived class will access the same static variable as the base class.
David Henry
David Henry
falkone,

why not just test it out yourself. This is what I do to
clarify how things really work. Only requires a very simple
program. Have fun!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.