Wednesday, February 3, 2016

Setter and Getter

Setter and Getter

Implement a class School, including the following attributes and methods:
  1. A private attribute name of type string.
  2. A setter method setName which expect a parameter name of type string.
  3. A getter method getName which expect no parameter and return the name of the school.


Example
School school = new School();
school.setName("MIT");
school.getName(); // should return "MIT" as a result.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class School {
    /*
     * Declare a private attribute *name* of type string.
     */
    // write your code here
     
    /**
     * Declare a setter method `setName` which expect a parameter *name*.
     */
    // write your code here
    
    /**
     * Declare a getter method `getName` which expect no parameter and return
     * the name of this school
     */
    // write your code here
    private String name;
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getName() {
        return this.name;
    }
    
}