标签:
classPerson{
String name;
int age;
int grade;
Person(){
System.out.println("Person的无参数构造函数");
}
Person(String name ,int age){
this.name = name;
this.age = age;
System.out.println("Person的有参数构造函数");
}
void eat(){
System.out.println("吃饭");
}
}
classStudent extends Person{
//在子类的构造函数当中,必须调用父类的构造函数
Student(){
super();
System.out.println("student的无参数构造函数");
}
Student(String name,int age,int grade){
//this.name = name;
//this.age = age;
super(name,age);
this.grade = grade;
}
}
classTest{
publicstaticvoid main(String args []){
Student student =newStudent("zhagnsan",18,3);
System.out.println(student.name);
System.out.println(student.age);
System.out.println(student.grade);
}
}
标签:
原文地址:http://www.cnblogs.com/arroneve/p/5815434.html