java 封装02

//Person.java
public class Person{
    private String name;
    private int age;
    private String sex;
    public void setName(String pname){
        name=pname;
    }
    public String getName(){
        return name;
    }
    public void setAge(int page){
        if (page >0){
        age=page;
        }
    }
}

//TestPerson.java
public class TestPerson{
    public static void main(String args[])
    {
        Person p1=new Person();
        p1.setName("xiao");
        System.out.println(p1.getName());
    }
}

 

posted @ 2015-09-18 23:34  Xiao|Deng  阅读(123)  评论(0编辑  收藏  举报