package com.wxd.text1;
public class text3 {
public static void main(String[] args){
demo d = new demo();
d.setAge(10);
d.setName("王晓东");
System.out.println("年龄:"+d.getAge()+" "+"姓名:"+d.getName());
}
}
class demo{
private int age;
private String name;
public int getAge(){
return age;
}
public void setAge(int age){
this.age=age;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public class text3 {
public static void main(String[] args){
demo d = new demo();
d.setAge(10);
d.setName("王晓东");
System.out.println("年龄:"+d.getAge()+" "+"姓名:"+d.getName());
}
}
class demo{
private int age;
private String name;
public int getAge(){
return age;
}
public void setAge(int age){
this.age=age;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
}
在编写中,保持代码的分装性,使用set和get来限制不正常访问,用if来设置输入的内容,保证内容的健壮性