2016-06-29
package com.java1995; /** * 学生类 * @author Administrator * */ public class Student { String name; String stuNo;//学号 int age; String pickName;//昵称 public Student(){ //调用父类的构造器 super(); //调用本类的构造器 //this(); } public Student(String name){ this.name=name; } public Student(String name,String stuNo){ this(name); this.stuNo=stuNo; } public Student(String name,String stuNo,int age){ this(name,stuNo); this.age=age; } public Student(String name,String stuNo,int age,String pickName){ this(name,stuNo,age); this.pickName=pickName; } }
package com.java1995; /** * 测试类 * @author Administrator * */ public class TestStudent { public static void main(String[] args) { Student s1=new Student(); printStudent(s1); Student s2=new Student("张三"); printStudent(s2); Student s3=new Student("张三","49"); printStudent(s3); Student s4=new Student("张三","49",12); printStudent(s4); Student s5=new Student("张三","49",12,"小张"); printStudent(s5); } public static void printStudent(Student s){ System.out.println("姓名: "+s.name); System.out.println("学号: "+s.stuNo); System.out.println("年龄: "+s.age); System.out.println("昵称: "+s.pickName); System.out.println("-----------华丽丽的分割线-----------------------"); } }
【参考资料】