Hello. I think my question is very simple, but I really did not find any solution after much research.
In Java, I have two concrete classes that extend an abstract class, as the example:
public class Animal {}
public class Dog extends Animal {
public void bark() {}
public void eat() {}
}
public class Cat extends Animal {
public void eat() {}
}
Only the Dog class has the bark () method.
I would like a parameter of a method to accept any Animal object, so I did this:
public void doSomething(Animal animal) {}
But I need this method to make the animal bark, if it's a dog, so I tried it, without success:
public void doSomething(Animal animal) {
animal.bark();
}
Is there any way to do what I want?
Thank you!