0

for example in the code below I want to get "Dog" or "Cat". How do I do that?

public class Animal { // insert code here } public class Dog extends Animal { // insert code here } public class Cat extends Animal { // insert code here } public class test { Animal animal = new Animal(); // how do I get the name of the subclass i.e. how to get that the // animal is a dog if it is in fact a dog??! } 
2
  • Also, in this case, it will be an Animal, not a Dog, not a Cat. Commented Apr 29, 2016 at 16:48
  • As Sotirios Delimanolis has said, you can't, because you have only created an instance of Animal. You have never created an instance of a subclass of Animal. Commented Apr 29, 2016 at 16:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.