【正文】
ss Father{ int a=100。 } public static void main(String[] arg){ Father x=new Father()。 (a of son is : +)。s super is : +())。 (a of son is :+)。s super is : +())。 public int getA(){ return 。 ()。} public static void main(String arg[]){ Detergent x=new Detergent()。 ()。 ()。 (Super class has:)。 } } class Cleanser{ private String s=new String(Cleaner)。} public void dilute(){append(dilute())。} public void scrub(){append(scrub())。 } public static void main(String[] args){ Cleanser x=new Cleanser()。 ()。 ()。 public void print(){ int a =5。 (InheritDemo2)。 ()。 } public static void main(String args[]){ InheritDemo3 id3 = new InheritDemo3()。 } } // //演示 this和 super關鍵字的使用 class SuperClass{ int a=3。 } } 運行結果 : SuperClass InheritDemo3 5 3 public class Testthis{ private int i=0。 return this。 } public static void main (String args[]){ Testthis x=new Testthis()。 } } 構造函數(shù)的繼承和重載 構造函數(shù)的重載: 目的:以不同的方法對類進行初始化 注:構造函數(shù)間可以互相調(diào)用,調(diào)用其他構造函數(shù)時,必須用 this 代替函數(shù)名,這時的 this并不代表地址,只是用來表示構造函數(shù)的名稱。 } Testthis2(fl