1
I’m looking to use inheritance with parent class being abstract. The point is that I’m using the toString()
superscript so that each print of child classes can print their respective data. But when I use "this
" within toString on the attributes it shows me that: String pessoas.Pessoa.nome
.
When I access, there will be a difference between Professor and another Employee, such as Administrator.
package pessoas;
public abstract class Pessoa {
protected String nome;
protected String matricula;
protected String cpf;
@Override
public abstract String toString();
//getters e setters
}
package pessoas;
import rh.Funcionario;
public class Professor extends Pessoa implements Funcionario{
@Override
public String toString() {
return this.nome + this.cpf + this.matricula;
}
@Override
public Double salario() {
// TODO Auto-generated method stub
return null;
}
}
Furthermore, I would also have to re-create the attributes in the child classes?
– Júnior Gorosh
I don’t understand very well. Your code is in error or you haven’t even run the same?
– Weslley Tavares
It’s incomplete because I thought it was relevant this part of the code that is the part I’m in doubt about the inheritance.
– Júnior Gorosh