關於This

//www.xinshuguang.org
//新曙光培訓@未央
interface myActionListener{}
//這個接口的作用是讓func2和func3有同樣類型的參數
//而後這種參數又由不同的類去實現
class myButton{
   public void func2(myActionListener k){System.out.println("func2: "+k);}
   public void func3(myActionListener k){System.out.println("func3: "+k);}
}
class AboutThis implements myActionListener{
   myButton oneButton;
   AboutThis(){
     System.out.println("新曙光@未央");
  
     class InsideThis implements myActionListener{
     InsideThis(){
     System.out.println("www.xinshuguang.org");
     }
   }
   oneButton =new myButton();

   oneButton.func2(this);
   //大家看看由此而產生的輸出
   //與最後一行產生的輸出比較,就知道
   //this就是AboutThis()這個類的實例
   oneButton.func3(new InsideThis());
   }//這之上是構造函數
  
   public static void main(String[] args){
     AboutThis 這個到底是誰=new AboutThis();
     System.out.println("main: "+這個到底是誰);
    
    
   }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章