packagecom.oop.Demo05;//person 人:父类//Java中默认直接或者间接继承objectpublicclassPerson/*extends Object*/{publicPerson(String name){System.out.println("Person无参执行了");}protectedString name ="kuangshen";//私有的东西无法传承!publicvoidprint(){System.out.println("Person");}}
packagecom.oop.Demo05;//Student is 人:派生类/子类//子类继承父类,就会拥有父亲的全部方法!publicclassStudentextendsPerson{publicStudent(){super("name");//调用了父亲的构造器,必须要在子类构造器的第一行System.out.println("Person无参执行了");}//隐藏代码:调用了父亲的无参构造privateString name ="qinjiang";publicvoidprint(){System.out.println("Student");}publicvoidtest1(){print();this.print();super.print();}publicvoidtest(String name){System.out.println(name);System.out.println(this.name);System.out.println(super.name);}}