Hello,
I have the following situation, I have an Animal object and I want to develop it for a Puppy:
public class Animal {
private boolean alive = true;
public boolean isAlive() {
return alive;
}
public void setAlive(boolean alive) {
this.alive = alive;
}
}
public abstract class Mamifero extends Animal {
public abstract void mamar();
}
public class Cachorro extends Mamifero {
@Override
public void mamar() {
System.out.println("Done");
}
}
I know this (below) does not work:
Animal meuAnimal = new Animal();
Cachorro cao = (Cachorro) meuAnimal;
But I do not want to have to instantiate a Dog and go attribute-to-attribute by filling it with the N data my Animal has.
Is there any way to make this evolution automatically?