What is used to change the state of private field in the class?
Answers
Answered by
0
Answer:
use setters and getters
Explanation:
Answered by
1
Accessors And Mutators in Java
Explanation:
Accessor method
- Accessor in programming language gets the value of a private data member.
- Accessors are commonly refereed as getters.
Syntax:
public int rollNo()
{
return rollNo;
}
Mutator method
- Mutator method sets the value of a private data member.
- Mutators are commonly refereed as setters.
Syntax:
public void set rollNo(int rollNo) {
this.rollNo = rollNo;
}
- The variables declared as private can not be accessed outside the class thus getter and setter methods are used.
Similar questions