For example I have a subclass named Lives
which uses the constructor of the superclass GLabel`:
public Lives(int lives, int xPosition, int yPosition){
super(lives+"", xPosition, yPosition);
this.lives = lives;
}
Within GLabel there is a variable for the font-size but the font is too small. I would like to change this. How do I know what the variable names are of the variables created in the superclass?
Edit: I realised that the methods should have getters and setters and that these should be documented. So my question is about the case in which there are no getters and setters and the instance variable is public.
JLabel
is a subclass ofJContainer
.JContainer
offers a public method named setFont(), so you can call it from any place in your program, where you have a reference to the label object (the Lives' constructor is a valid place though).The possbility to change a super class' attribute depends on its visibilty (for example protected) and available accessor methods (for example
getName()
andsetName()
).If an attribute/accessor was declared public or protected, you can change it directly from inside the subclass. In case of default visibilty, the subclass needs to be in the same package as the super class to manipulate the respective attribute.