this关键字的使用
*可以调用本类中的方法
*可以调用构造方法,调用构造方法时this()要放在构造方法的首行.
例如:
class Student{
Student(){
System.out.println("被this调用了");
}
Student(String n,int b){
this();//调用了Student()构造方法
语句1;
语句2;
语句N;
}
}
*在使用this调用构造方法时,至少留一个构造方法(里面是不包含this),作为构造方法的出口。另外如果使用this调用构造方法,则必须放在构造方法的首行。
*this表示当前对象:谁调用了这个方法,则this就表示那个对象
本文出自 “12171007” 博客,谢绝转载!
原文:http://12181007.blog.51cto.com/12171007/1903175