1
The function super()
serves to call the parent builder and verify suitable signatures.
public class Pessoa {
private String nome;
private String endereco;
private String telefone;
private String cpf;
private String telefoneCelular;
public Pessoa(String nome, String endereco, String telefone) {
this.nome = nome;
this.endereco = endereco;
this.telefone = telefone;
}
}
public class Aluno extends Pessoa {
public Aluno() {
super();
}
public Aluno(String curso, double[] notas, String nome, String endereco, String telefone) {
super(nome, endereco, telefone);
this.curso = curso;
this.notas = notas;
}
}
Although I know it works this way, I don’t understand how signature verification is done when the scope variables are different.
public class Aluno extends Pessoa {
public Aluno() {
super();
}
public Aluno(String curso, double[] notas, String teste1, String teste2, String teste3) {
super(teste1, teste2, teste3);
this.curso = curso;
this.notas = notas;
}
}
The check would be in the order in which the variables are declared within the super function? , because they are all of the same type (String
).
- teste1 = name
- teste2 = address
- teste3 = phone
Exactly, if you pass teste2 as name, teste1 as phone and teste3 as address, the assignments will be made "wrong" because your implementation was made like this. Java does not check for the name you gave to the attribute to its type, if the type hits, it will assign the value, if not, it does not even compile.
– user28595
Then the order I declare them within Student(...) will not matter, only will the statement be of importance within the super function()?.
– Gustavo
If you change the order of the student constructor arguments in no way affects those of the super, since in the implementation within the student constructor, you correctly pass the arguments to the super().
– user28595
Thank you very much for the clarifications.
– Gustavo