public animal{
String name;
String species;
public introduction(){
System.out.println("Hi, my name is" + name +", i am a " + species);
}
}
public dog extends animal{
String species = "dog";
}
I am wondering if i were to build more child classes like cat, bird etc, with with their unique species variable. If there a way whereby I can make them self-introduce different according to their species?
I understand that I am asking a parent class to access a child-class attribute, which seems to defeat the purpose of inheritance in the first place, but I am not sure what is a more elegant way of doing this.