Sunday 15 April 2012

java - How to access and change the instance variables created within a superconstructor? -



java - How to access and change the instance variables created within a superconstructor? -

for illustration have subclass named lives uses constructor of superclass glabel`:

public lives(int lives, int xposition, int yposition){ super(lives+"", xposition, yposition); this.lives = lives; }

within glabel there variable font-size font small. alter this. how know variable names of variables created in superclass?

edit: realised methods should have getters , setters , these should documented. question case in there no getters , setters , instance variable public.

jlabel subclass of jcontainer. jcontainer offers public method named setfont(), can phone call place in program, have reference label object (the lives' constructor valid place though).

the possbility alter super class' attribute depends on visibilty (for illustration protected) , available accessor methods (for illustration getname() , setname() ).

if attribute/accessor declared public or protected, can alter straight within subclass. in case of default visibilty, subclass needs in same bundle super class manipulate respective attribute.

java super

No comments:

Post a Comment