java 中 this 类名 对象名 的作用
来源:互联网 发布:拍大师软件 编辑:程序博客网 时间:2024/05/22 16:52
this 表示“当前对象”,不能用在静态的方法中。
对象象你知道的就有很多拉,变量拉,线程等等。
1.This用来表示全局变量
public class TestClass{ int x,y; void testShow(int x,int y){ this.x=x; //this.x 就是我们上 int x,y;中的X 。x是我们传来的x this.y=y; }}
2.
public class TestClass { int x; int y; static void showtest(TestClass tc){ System.out.println(tc.x+" "+tc.y); } void seeit(){ showtest(this); } public static void main(String[] args){ TestClass p=new TestClass(); p.x=9; p.y=10; p.seeit(); }}
这段代码中showtest(this),这里的this就是把当前实例化 的 p传给了showtest方法,从而就运行了。
类名用来访问静态成员;
public class Test {
private float f = 1.0f;
int m = 12;
static int n = 1;
//public static void main(String[] args) {
public void main(String[] argc){
Test t = new Test();
Test.n = 10;
}
}
对象名可以访问静态和非静态成员
public class Test {
private float f = 1.0f;
int m = 12;
static int n = 1;
//public static void main(String[] args) {
public void main(String[] argc){
Test t = new Test();
Test.n = 10;
t.m = 10;
t.n = 10;
}
}
- java 中 this 类名 对象名 的作用
- Java的 类名.this
- &类名::成员名的作用
- 类对象,类名.class与类名.this
- {类名}.this 的用法
- 类名.this 的使用
- 类名.this 的使用
- 类名.this 的使用
- 类名.this 的使用
- 类名.this的使用
- this与类名.this的异同
- 类名.this与this的区别
- Java语言中,包名、类名、接口名、方法名、变量名,以及常量名的命名有何规范的命名习惯
- Java语言中,包名、类名、接口名、方法名、变量名,以及常量名的命名有何规范的命名习惯
- 构造方法(java中跟类名一样的方法名的作用)
- 构造方法(java中跟类名一样的方法名的作用)
- 类名.this
- 类名.this
- PHP 循环
- Js获取url参数
- link list and wait queue
- PHP 函数
- 一、信号(上)转载
- java 中 this 类名 对象名 的作用
- c++文件操作
- JSP页面缓存技术--浏览器缓存(转)
- Hibernate与JDO肩并肩
- 二、信号(下)转载
- Android实战(1)_Ubuntu10.10下真机调试
- DT
- vs2005的消息映射
- 第一篇文章,记述自己心情的开始