1
Hello. I believe my doubt 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 method parameter 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 this, unsuccessfully:
public void doSomething(Animal animal) {
animal.bark();
}
Is there any way I can do what I want?
Thank you!
I believe that creating an Equal() method for your animal, and if Animal.What(Dog) == true, barking will work.
– pmargreff
http://javafree.uol.com.br/topic-3932-Comparar-variaveis--ou-equals.html
– pmargreff