Inheritence and variable

Omid Roozmand Hamid

Greenhorn

Posts: 1

posted 3 years ago

Assuming that we have two classes B and C which inherit from class A. What is the best way to pass a parameter from an object of class B to an object of class C by the use of class A without using static variable and without defining a get function in B?

Mike. J. Thompson

Bartender

Posts: 689

17

posted 3 years ago

Is this a a homework question? You will probably have to give a bit of context to what you are trying to achieve here.

Two different objects are not linked though (even if they inherit from the same super class, or even if they were instances of the same class). The only way to pass a value from one class to another is for the first class to have a reference to the second class.

But without knowing what you are trying to achieve I can't really be more specific.