private
and set are distinct concepts:
private
To keyword private
is what we call Access Modifier.
There are basically three access modifiers: public
, protected
and private
:
public
: this is the most "open" access modifier that exists in Java. Any class can access the member that has this access modifier. You do not need to be a child class of the class that has members with this access modifier (also known as public members) not being in the same package;
protected
: this access modifier restricts access to the member in which it is used so that it is accessed only by the classes that inherit from the class that has the members with this access modifier and the classes that are in the same package;
private
: This access modifier is the most "restricted" modifier in Java. It restricts the access of members who have this modifier to only the class itself and the classes that are in the same package;
set
The term set (in that case) concerns the methods setters.
In Java there is the concept of encapsulation, which says (simply) that its attributes must be accessed exclusively by methods if they are to be accessed outside the class itself.
For example:
public class Pessoa {
private String nome;
public String getNome() {
return nome;
}
public void setNome(String nome) { //método "setter"
this.nome = nome;
}
}
What you (probably) want to do is a method Setter private:
private void setNota(double nota) {
estud.notas[0] = nota;
}
Considering the two topics (the access modifier private
and the method Setter), It’s up to you to decide if you really want to do this.
I particularly find it silly to access a member of your own class through a method Setter.
If you were to "settar" the value of estud.notas[0]
through another class, then yes it would be advantage/correct to use a Setter for this and would also need to check the correct access modifier for the scenario.
No, I wouldn’t be. I wouldn’t go anywhere near that. In order to answer this question, explain what your classes are and how they relate. Your classes are
Estudante
andNota
? By the way, if notes is an array, probably using a Setter won’t be the best way.– Victor Stafusa