JAvaパッケージprivateメンバー変数setterとgetterメソッドテスト

3878 ワード

class Person {
    private String name = "  ";
    private int age = 30;
    private int high = 170;
    private int weight = 120;
    public String getValue() {
        return name;
    }
    public int getValue1() {
        return age;
    }
    public int getValue2() {
        return high;
    }
    public int getValue3() {
        return weight;
    }
    public String setValue(String name) {
        this.name = name;
        return name;
    }
    public int setValue1(int age) {
        this.age = age;
        return age;
    }
    public int setValue2(int high) {
        this.high = high;
        return high;
    }
    public int setValue3(int weight) {
        this.weight = weight;
        return weight;

    }

}
public class TestPerson{
    public static void main(String[] args) {
        Person t = new Person();
        System.out.println("  :"+t.getValue());
        System.out.println("  :"+t.getValue1());
        System.out.println("  :"+t.getValue2());
        System.out.println("  :"+t.getValue3());
        System.out.println("     :"+t.setValue("  "));
        System.out.println("     :"+t.setValue1(20));
        System.out.println("     :"+t.setValue2(180));
        System.out.println("     :"+t.setValue3(150));  
    }
}