父类
package com. mypackage. oop. demo06 ; public class Person06 { public Person06 ( ) { System . out. println ( "Person06无参执行了" ) ; } protected String name = "hexioahei" ; public void print ( ) { System . out. println ( "Person" ) ; }
}
子类
package com. mypackage. oop. demo06 ; public class Student06 extends Person06 { public Student06 ( ) { System . out. println ( "Student06无参执行了" ) ; }
private String name = "jack" ; public void print ( ) { System . out. println ( "Student" ) ; } public void test2 ( ) { print ( ) ; this . print ( ) ; super . print ( ) ; } public void test ( String name) { System . out. println ( name) ; System . out. println ( this . name) ; System . out. println ( super . name) ; }
}
应用
package com. mypackage. oop. demo06 ; import com. mypackage. oop. demo06. Student06 ; public class Application06 { public static void main ( String [ ] args) { Student06 student06 = new Student06 ( ) ; student06. test ( "何小黑" ) ; System . out. println ( "------------" ) ; student06. test2 ( ) ; } }
Person06 无参执行了
Student06 无参执行了
何小黑
jack
hexioahei
-- -- -- -- -- --
Student
Student
Person 进程已结束, 退出代码0