package pack1;
public class Student {
private String name;
private int age; //构造方法
//如果没有任何构造函数,系统会自动给一个无参构造函数
public Student(){
this.name="";
this.age=0;
}
public Student(String name,int age){
this.name=name;
this.age=age;
} public void show(){
System.out.println(name+","+age);
}
}
package pack1;
//测试学生类 public class StudentDemo {
public static void main(String[] args) {
// 创建对象
Student s1=new Student();
Student s2=new Student("njt",22);
s1.show(); // ,0
s2.show(); // njt,22
}
}
05-27 09:43