• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritence and variable  RSS feed

 
Omid Roozmand Hamid
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Junilu Lacar
Sheriff
Posts: 11493
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

This looks like homework and as such you will not get an outright answer here. We encourage everyone to DoYourOwnHomework (←click on that link to read our guideline about this).

I suspect you already have the answer in front of you since the subject of this topic that you gave has all the clues that you need.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!