标签:修改 年龄 rgs system student tag === public his
这样的标准类也叫做Java Bean
标准类:
public class Student{
private String name;//姓名
private int age;//年龄
public Student(){
//无参构造方法
}
public Student(String name ,int age ){
this.name = name;
this.age = age;
}//有参构造方法
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}//姓名
public int getAge(){
return age;
}
public void setAge(int age){
this.age = age;
}//年龄
}
//==================//
public class CaiNiao{
public static void main(String[] args){
Student stu1 = new Student();
stu1.setName("菜鸟");
stu1.setAge(18);
System.out.println("姓名:" + stu1.getName()+",年龄:"+stu1.getAge());
//第二种方法
student stu2 = new Student("传奇",28);
System.out.println("姓名:" + stu2.getName()+",年龄:"+stu2.getAge());
stu2.setAge(22);//修改后
System.out.println("姓名:" + stu2.getName()+",年龄:"+stu2.getAge());
}
}
标签:修改 年龄 rgs system student tag === public his
原文地址:https://www.cnblogs.com/cainiao-chuanqi/p/11073989.html