Getter or Accessor methods and Setter or Mutator methods are public methods. Getter or Accessor methods are used to retrieve the values of a private variable. In the question, if name and rollNo are already assigned values, then you can use these methods to get the values. They must have a return type. For example: public String getName(){ return name; // this returns the value stored in name variable to the caller method } public int getRollNo(){ return rollNo; // this returns the value stored in rollNo variable to the caller method } Setter methods are used to change the value of private variables. They do not have return types. For example, public void setMarks(int marks){ this.marks = marks; // assigns some values to the marks variable } The this keyword is used to overcome name-space collisions. Hope this answers your questions. Regards. | 0 |
By: [email protected] On: Tue Mar 14 14:32:19 IST 2017 0 0 0 | 0 |
Are You Satisfied :0Yes0No |