Inheritance and stuff

M

mnml

Hi,
I have two class and I would like to use one of the Variable from the
child class in one of the parent class's function,
Is there a way to do that, should I use an Interface?

Regards.
 
M

mnml

mnml wrote:

..


Can you describe an actual example* where that makes
any sense?

* Concrete, as opposed to abstract.

ok then I have a Parent class : Elements
and i have a child class : Player

The pos_x and the pos_y of my Player are part of defined in the Player
class ( pos_x = 20; pos_y = 20;// as a starting position )

In my Elements class I have a Function using that value but here is my
problem: if I don't define int pos_x in the Elements class it return
me an error because it can't find the Variable. If I define it it
doesn't care about the value set in my Player class when i use the
actual function.
 
A

Andrew Thompson

mnml wrote:
...
ok then I have a Parent class : Elements

Elements? What does that mean?
and i have a child class : Player

I could understand Player being sub-classed to
PokerPlayer and FootBallPlayer, or perhaps
AudioPlayer and VideoPlayer, but what is the
relationship between an 'Element' and a Player?

( If it makes sense to have the Element access the
attributes within a method, perhaps they should be
attributes of Element, rather than Player. And as
an aside, how would the Player class in my example,
decide whether to use the defaultPlayTime of, for
example, AudioPlayer or VideoPlayer? )

BTW
- The word 'I' should always be upper case.
- 'OK' is also upper case.
- A ..
- Function in Java is more commonly referred to as a method.
- Variable -> attribute

--
Andrew Thompson
http://www.physci.org/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200712/1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top