【JAVA學習路-think in java】p85:類中不同方法的調用手段 this

package pkg;

class car{
	
	void mtd2(){
		System.out.println("hello,world");
	}
	void mtd1() {
		
		System.out.println("Invoke 1st method by THIS:");
		this.mtd2();// the object itself invoke this, not recommended
		System.out.println("Directly invoke 2nd method:");
		mtd2();
	}
	
}


public class p85 {
	public static void main(String[] args) {
		
		car toyota=new car();
		toyota.mtd1();
		
	}
	
}

OUTPUT:

Invoke 1st method by THIS:
hello,world
Directly invoke 2nd method:
hello,world
 

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