In object-oriented programming in Java, when I create a particular attribute or private field, without its methods getter
and setter
do you have to set the attribute to final
or do not require?
For example:
public class Pessoa {
private String nome;
private String endereco;
private int idade;
private double salario;
public Pessoa(String nome, String endereco, int idade, double salario) {
this.nome = nome;
this.endereco = endereco;
this.idade = idade;
this.salario = salario;
}
}
In this class above as you see, it does not have the methods getter
and setter
of the respective attributes or fields, in which case it would be necessary to define them as final
?