I read the tutorial stuff about abstract classes and am a little unclear on something..
I have an abstract class
abstract class Master implements ActionListener {
static Point p;
static JFrame glass;
/* code to define glass and a mouseListener to it.
The mouselistener essentially registers the mouseclick
and point P where it happened */
}
And the I extend some others
class FirstMaster extends Master {
/* some definitions and stuff */
}
class SecondMaster extends Master {
/* some definitions and stuff */
}
My questions
- Is the static variable p and JFrame specific to both FirstMaster and SecondMaster, that is Master.p, FirstMaster.p and SecondMaster.p are the one and the same Point with a single memory location?
- Each (instance of) First and Second Master is an independent ActionListener and needs to define the associated method - correct?
- Without the modifiers static it would be equivalent to simply copy and paste the code in Master into the First and Second and get rid of the extends?
Sorry for the newbie question but I didnt see an example to figure it out definitively.
EDIT: Since there is a lot of info below I thought I would summarize my understanding of the answers for the benefit of subsequent readers (and please correct if I am mistaken)
- There is only one p. The extension does not create a new static p for each subclass and this fact is independent of the abstract modifier.
- the method actionPerformed() can be specified in Master or in BOTH First and Second definitions. Specifying it in First and Second allows the response to the action to be unique to each subclass.
- Ignoring the complication with the implement ActionListener, the answer is yes, although this would result in redundant code.
Thanks to all.