I'm starting in the Java language and I came across a problem. It is the following: I have 1 class that calls Vehicle, it has the attribute tag (string) and has 3 classes that inherit it, in the case are: Car (qtdPort int), Moto (qtdCilindradas int), Boat (potMotor int) and I will have a vector [] to store the inserted vehicles, my problem is the following, how do I insert into the vector [] an object of the type Car, or Moto, or Boat, specifically? I have thought of the following code, but it is only used to insert normal values, when there is no inheritance, what would the code look like to insert into a vector when there is an inheritance?
public void insereVeiculo(Veiculo veiculo)
{
int contador = 0;
for (int i = 0; i < this.vetVeiculo.length; i++)
{
if(this.vetVeiculo[i] == null)
break;
else
contador++;
}
this.vetVeiculo[contador] = veiculo;
}