一1.package edu.xucd;
/*
类的封装
1成员变量必须私有化private修饰
2使用gerrer setter提供对外的访问方式
*/
public class Demo {
public String name;
public int age;
//设置值seetter
public void setName(String 小明){
this.name=name;
}
//获取值getter
public String getName(){
return this.name;
}
public void setAge(int age){
this.age=age;
}
public int getAge() {
return this.age;
}
}
2.测试:package edu.xucd;
public class testDemo {
public static void main(String[] args) {
/* Demo demo=new Demo();
demo.name="小明";
demo.age=99;
System.out.println(demo.name);
System.out.println(demo.age);*/
Demo demo=new Demo();
demo.setName("小明");
demo.setAge(19);
System.out.println(demo.getName());
System.out.println(demo.getAge());
}
}