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

2014/9/30

Subclass Turtle does not inherit the methods from class Animal

MSacramento MSacramento

2014/9/30

#
I am puzzled as to why my subclass turtle does not inherit the three methods (atWorldEdge(), canSee(), and eat()) from the Animal class. Please help, I am just stuck here!
davmac davmac

2014/9/30

#
Does your turtle class (which should be called Turtle, with a capital 'T', by the way) actually 'extend Animal'?
MSacramento MSacramento

2014/9/30

#
I am new on Greenfoot online video tutorials which I am trying to follow as quick as I can. Yes (Java rule on class naming, of course)! In fact it is all now sorted, by just copying the Animal class version 1.0 of Dr Michael Kolling and pasting it into the empty Act method of the Animal class version I got on my system. I've found it on one of his scenarios. I wish such file would have been posted on the Support Classes web page for all to download. Thanks anyway
danpost danpost

2014/9/30

#
MSacramento wrote...
I wish such file would have been posted on the Support Classes web page for all to download. Thanks anyway
The greenfoot Actor class has had 'isTouching' and 'removeTouching' methods included in them in versions 2.3 and 2.4. Also, in 2.4, included was an 'isAtEdge' method. So. the Animal class is kind of obsolete ('isTouching' is 'canSee', 'removeTouching' is 'eat' and 'isAtEdge' is 'atWorldEdge').
davmac davmac

2014/9/30

#
In fact it is all now sorted, by just copying the Animal class version 1.0 of Dr Michael Kolling and pasting it into the empty Act method of the Animal class
This doesn't sound like the right way to use the Animal class. You should have your Turtle class extend Animal (so Turtle is a subclass of Animal, instead of Actor directly). You should not need to modify the Animal class itself.
MSacramento MSacramento

2014/10/1

#
Thank you danpost for letting me know about Greenfoot 2.4 and its additional methods, which version I have now installed. As davmac does rightly remind me, indeed my Turtle inherits from Animal, which inherits from Actor, but these two classes do come with empty Act methods, which startled me somewhat. So I proceeded as instructed in the video tutorials, namely, empty the contents on the Animal class first, then paste the Animal class version 1.0 by Michael Kolling, and it worked. I guess I should try invoke isTouching, removeTouching, and isAtEdge methods in the Turtle class, which inherits directly from Actor, right?
You need to login to post a reply.