Think in java 答案

    技术2022-05-11  136

    阅前声明: http://blog.csdn.net/heimaoxiaozi/archive/2007/01/19/1487884.aspx 

    /****************** Exercise 9 ****************** * Create a class with two methods. Within the * first method, call the second method twice: * the first time without using this, and the * second time using this. ***********************************************/public class E09_ThisMethodCall {  public void a() {    b();    this.b();  }  public void b() {    System.out.println("b() called");  }  public static void main(String args[]) {    new E09_ThisMethodCall().a();  }}

    //+M java E09_ThisMethodCall

     

    **This exercise just shows how this refers to the current object (I certainly don’t recommend the this.b( ) form of method call). Note in main( ) how the object is created just to make the single method call, and therefore I don’t have to hold on to the object reference.


    最新回复(0)