java中this.value_java中关键字this的用法
java中,使用this的地方,完全可以不使用this,this代表當前對象,對于當前對象的方法或者屬性,個人覺得用不用this都沒有多大關系,示例代碼如下:
package testTHIS;
public class TestTHIS {
int flag = 0;
public static void main(String[] args) {
Test test = new Test();
test.main();
TestTHIS tt = new TestTHIS();
tt.say(); // 不能使用this.say();
}
public void say() {
MyTest mt = new MyTest();
mt.main();
int i = this.flag;
int k = flag;
}
}
class Test {
public void main() {
say1();
this.say1();
say2();
this.say2();
say3();
this.say3();
say4();
this.say4();
}
public void say1() {
System.out.println("111111111111111");
}
protected void say2() {
System.out.println("222222222222222");
}
void say3() {
System.out.println("333333333333333");
}
private void say4() {
System.out.println("444444444444444");
}
}
class MyTest extends Test {
@Override
public void main() {
this.say1();
}
}
總結
以上是生活随笔為你收集整理的java中this.value_java中关键字this的用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java Mina sftp_java
- 下一篇: java下发报文_java报文的发送和接