1、子类中无参构造函数,可直接继承父类中无参构造函数,前提是所有变量均为public
如下:父类Student中有空构造函数Student(),子类Pupil中有空构造函数Pupil(),后者会继承前者。
注:在本例中,父类中的name、height都是public的,如果是private就无法直接继承。
package javastudy;
public class ConfunDemo5 {
public static void main(String[] args) {
Pupil z=new Pupil();
z.show();
}
}//需要获取资料的朋友请加Q君样:290194256*
class Student{
//父类Student
public String name;
public int height;
public Student()
{
this.name="";
this.height=0;
}
}
class Pupil extends Student{
//子类Pupil
private int score;
public Pupil