This site requires JavaScript, please enable it in your browser!
Greenfoot back
s_zaf
s_zaf wrote ...

2017/11/15

Subclass method

s_zaf s_zaf

2017/11/15

#
How to use/add a method in the subclass when it's not present in the superclass(Actor)? The constructor in the subclass calls the superclass constructor so it uses the superclass act() method where the subclass method is not present. So, it's not working.
Super_Hippo Super_Hippo

2017/11/15

#
Create an act method in the subclass and it will override the act method of the superclass. In its own act method, it can use all methods from that class.
s_zaf s_zaf

2017/11/15

#
yes I did it, this way it works, but for this i have to write all the superclass act() methods in the subclass act() which I do not want, is there any other way ?
Super_Hippo Super_Hippo

2017/11/15

#
In the subclass's act method, you can call the superclass's act method using 'super.act();'.
public void act()
{
    //something all subclasses do
    super.act();
    
    //something only this subclass does
    //....
}
s_zaf s_zaf

2017/11/15

#
thanks!!
You need to login to post a reply.