Imagine I have this:
public class Animal {
private String racaAnimal;
private String corAnimal;
public String getCorAnimal() {
return this.corAnimal;
}
public String getRacaAnimal() {
return this.racaAnimal;
}
public Animal getAnimaisCliente(int indice) {
return this.animaisCliente[indice];
}
}
public class Estimacao extends Animal{
private String nomeAnimal;
public String getNomeAnimal() {
return nomeAnimal;
}
}
public class Cliente{
private Animal[] animaisCliente;
}
Constructors aren’t showing but they are working fine.
I have one arraylist that holds all Cliente
ArrayList<Cliente> clientes = new ArrayList<Cliente>();
And a animal is created like this
Estimacao animaisEstimacao = new Estimacao(nomeAnimal,racaAnimal,corAnimal);
and then its added to the array of Animal in Cliente
Now if I do this:
System.out.println(" Raça: " + clientes.get(0).getAnimaisCliente(0).getRacaAnimal());
It works.
But how can i get nomeAnimal from class Estimacao?
If i put
System.out.println(" Nome: " + clientes.get(0).getAnimaisCliente(0).getNomeAnimal());
it do not works.
From a subclass we can get things from the super class but the other way arroud? is it possible?
Try