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

2013/6/9

calling a method of a particular instance

dat2357 dat2357

2013/6/9

#
I have a class called Animal. It has a private instance variable called 'kind' and a accessor method called getKind(). In the World's contructor several instances of the Animal class are made and placed in the world. There is another class called Hunter. I want some of the code in Hunter to know when it has encountered a particular instance of Animal and then call that instance's getKind() method. Any suggestions?
bourne bourne

2013/6/9

#
For the Hunter, have something like:
public void act()
{
    Animal animal = (Animal)getOneIntersectingObject(Animal.class);
    if (animal != null)
    {
        animal.getKind();
    }
}
dat2357 dat2357

2013/6/9

#
thanks
You need to login to post a reply.