I have three classes (Carnivore, Herbivore, and Plant) that extend another class (Organism). How can I tell which subclass an
Carnivore
Herbivore
Plant
Organism
You can use the instanceof keyword.
instanceof
Note, however, that needing to use this is often a sign of a bad design. You should typically write method overrides in each of your derived classes so that you don't explicitly need to check which class something is.