首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java 种与对象-this关键字

2012-12-25 
java 类与对象---this关键字在类的方法定义中使用的this关键字?代表使用该方法的对象的引用、当必须指出当

java 类与对象---this关键字

在类的方法定义中使用的this关键字?代表使用该方法的对象的引用、

当必须指出当前使用方法的对象是谁时使用this、

有时使用this可以处理方法中成员变量和参数重名的情况。

this可以看作是一个变量,它的值是当前对象的引用。

public class Dog{    int i = 0;    Dog(int i){        this.i = i;    }    Dog sceam(){        i++;        return this;    }    void print(){        System.out.println("i = "+i);    }    public static void main(String[] args){        Dog dog = new Dog(49);        Dog.sceam().sceam().print();    }}
?

热点排行