package kaoshi; /** ************************************ * @author Hejing * @date December 24, 2017 * @class fisrt.java * ************************************ */ class Student{ String name; int age; public Student(String name,int age) { this.name=name; this.age=age; } public void study() { System.out.println("Student's learning method is: "); } public void show() { System.out.println("Name is "+name); System.out.println("age is "+age); } } class Benkesheng extends Student{ String dept; String disagree; public Benkesheng(String name,int age,String dept,String disagree) { super(name, age); this.dept=dept; this.disagree=disagree; } public void study() { System.out.println("Undergraduate study method is: "); } public void show() { super.show(); System.out.println("Professional is"+dept); System.out.println("Degree is"+disagree); } } class Yanjiusheng extends Benkesheng{ String direction; public Yanjiusheng(String name,int age,String dept,String disagree,String direction) { super(name, age,dept,disagree); this.direction =direction; } public void study() { System.out.println("Postgraduate study method is: "); } public void show() { super.show(); System.out.println("方向"+direction); } } public class fisrt { public static void main(String[] args) { Student s1=new Student("张三",18); Benkesheng b1=new Benkesheng("Zhang Si",20,"Computer","Software degree"); Yanjiusheng y1=new Yanjiusheng("Zhang Wu",20,"Computer","Software Degree","Artificial Intelligence"); s1.study(); s1.show(); b1.study(); b1.show(); y1.study(); y1.show(); } }
The subclass constructor calls the superclass constructor (use of the super keyword)
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325192067&siteId=291194637
Ranking