大家好,我是一名JAVA的初学者,关于this的使用有点不了解,据初步了解this的使用是类似于C的指针功能,那么请问它是具体怎样指法的?可以详细的介绍一下它的使用方法吗?是怎样使用的?谢谢!

解决方案 »

  1.   

    this:所在类自身的一个实例对象或者指类本身
    1.构造 this(a,b....)
    2.方法 this.function(a,b...);
      

  2.   

    this表示的是当前对象本身的一个引用
      

  3.   

    本类的一个实例,this实际上是Class.forName("yourClass").newInstance()
      

  4.   

    this是一个实例值,用来在成员函数类内部指向当前的对象.可以做为返回值
    可以做为实例值引用成员变量和成员函数在成员函数里 写 this.a;//a 是 成员变量 this.fun();//fun 是 成员函数
      一般情况下没必要要前面的this.
    但是java允许成员函数的参数和成员变量同名. 例如
    void fun(int a)
    {
      this.a = a;  // 带this是成员变量 , 不带的是参数 这样就区别开了
    }
      

  5.   

    this就是当前对象的一个引用,public class ThisShow {      public String thisstring = "the string of this and ThisShow";
          
          ThisShow(){
                  System.out.println(this.thisstring);
          }           
    }public class Test {
         public static void main (String argv[]){
            ThisShow myObject = new ThisShow();
            System.out.println(myObject.thisstring);
    }/** 在类ThisShow里的this和类Test里的myObject表示同样的意思.*/