2
package br.com.cursoemvideo;
public class Olho {
private String cor;
private boolean funciona;
public String getCor() {
return cor;
}
public void setCor(String cor) {
this.cor = cor;
}
public Boolean getFunciona() {
return funciona;
}
public void setFunciona(Boolean funciona) {
this.funciona = funciona;
}
public Olho(String cor, Boolean funciona) {
this.cor = cor;
this.funciona = funciona;
}
public void verificar() {
System.out.println("A cor do olho é: " +this.getCor());
System.out.println("O olho funciona ? " +this.getFunciona());
}
}
Class of the main programme:
package br.com.cursoemvideo;
public class Aula_test {
public static void main(String[] args) {
Olho[] ol = new Olho[1];
ol[0] = new Olho("Castanho",true);
ol[1] = new Olho("Azul",false);
ol[0].verificar();
}
}
And the error appears:
Exception in thread "main" java.lang.Arrayindexoutofboundsexception: 1 at br.com.cursoemvideo.Aula_test.main(Aula_test.java:9)
It worked, but now I’m confused. I took an online course in which the teacher says that the vector starts at position 0. So I thought that if I wanted a vector with 2 elements it would have to have index 1 (the count being 0.1)
– Toni_Emmanuel
That’s what I said (I realized I was confusing it with index), there you are not putting an index, you are putting how many elements should fit in this array, are separate things.
– Maniero
True, now I understand. Thank you !
– Toni_Emmanuel