this
来源:互联网 发布:曼隆学院 知乎 编辑:程序博客网 时间:2024/06/05 23:04
this:指代当前对象,哪个对象调用方法指的就是哪个对象
只能用在方法中,方法中访问成员变量之前默认有个this.
this的用法:
2)this.方法名()--------------调用方法
3)this()---------------------调用构造方法
this关键字主要有三个应用:
(1)this调用本类中的属性,也就是类中的成员变量;
(2)this调用本类中的其他方法;
(3)this调用本类中的其他构造方法,调用时要放在构造方法的首行。
Public Class Student {
String name; //定义一个成员变量name
private void SetName(String name) { //定义一个参数(局部变量)name
this.name=name; //将局部变量的值传递给成员变量
}
}
从这个应用中,this关键字其代表的就是对象的名字,这里的this关键字含义就是对象名student,为此this.name就表示student.name
阅读全文
0 0
- this
- this
- this
- this
- this
- this
- this
- this
- this
- this
- this
- $(this)
- this
- this
- this
- this
- $(this)
- this
- DStream 生成 RDD 实例详解
- 每日一练_08
- 设置centos7的网络连接
- 1039. 到底买不买(20)
- 窗口
- this
- 【KM算法 模板】HDU
- Split Linked List in Parts(LeetCode725)
- 编程求出1+2+3...+n的值
- contine语句
- C++多线程中调用python api函数 GIL的使用
- 多线程下载
- 多项式求和
- 1040. 有几个PAT(25)