Lets say i have these 3 classes
class Human
public void eat()
class Lawyer extends Human
public void beEvil()
class Murderer extends Human
public void beEvil()
public void kill()
Now i have a handler for actions, and i want to handle actions without knowing what i am. So for example:
handleBeEvil(Human human)
{
..
human.beEvil(); //wont obviously work
..
}
In as3 for example, i woud use
handleBeEvil(Object human)
{
human.beEvil(); //would pass compiler, work or break runtime
}
Whats the best way to accomplish this in Java? I would like to avoid putting all the declerations in the Human class.
Create an interface and have both
LawyerandMurdererimplement it (i.e.class Lawyer extends Human implements Evil):Then your method would be