Class children have different features(its own unique functions), how to use it from Parent class?
Class children have different features(its own unique functions), I want to know how to use it from Parent class? I have parent Class Animal. Two children Class, Dog and Cat. Dog has a function grab(). Cat has a function kick(). If I have to use Class Animal to manage all objects I have, then I have to add both functions grab() and kick() to Class Animal? Then do I have to check the class of the object each time, before I execute grab()? Because if it is a cat, grab() does nothing. Follow up question, how should I check the class? Use instanceof ,getClass(), override equal(obj), switch? Also, another question, what to do if I checked and found that the object is a cat? My friend suggests that uses Exception to skip. But my teacher doesn't recommend this method. I know it is a lot to ask. But I just want to know if I am on the right track. If I should use Interface or abstract class, please let me know.