11
If an abstract class cannot be instantiated, can creating a constructor method for this abstract class be regarded as good practice or not? If so, why are we creating the implementation of this method?
Below is an excerpt of code that illustrates my question:
public abstract class Funcionario {
private String nome;
private int numeroRegistro;
public Funcionario(int numeroRegistro) {
setNumeroRegistro(numeroRegistro);
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public int getNumeroRegistro() {
return numeroRegistro;
}
public void setNumeroRegistro(int numeroRegistro) {
this.numeroRegistro = numeroRegistro;
}
public abstract double obterSalarioBruto();
@Override
public String toString() {
return "Funcionario [getNome()=" + getNome() + ", getNumeroRegistro()=" + getNumeroRegistro() + "]";
}
}
I believe it is unnecessary unless you will put values in the attributes only in the parent class, for example, which I find unlikely.
– Giancarlo Abel Giulian
For this question no.
– Duds