你要知道每一个类里面的this到底是什么意思看你的理解是错误的!注意:对于继承过的类!这些有继承关系的类里面的this都是代表着最后一个new出对象时的那个对象!我写了3个类!你看看结果就知道了!
Person类
package question;
public class Person {
private int uid;
private String name;
public Person() {
super(); //这里是Object类默认构造函数
System.out.println("当前对象的简单名:"+this.getClass().getSimpleName());
System.out.println("当前对象的复杂名:"+this.getClass().getName());
}
}
Student类
package question;
public class Student extends Person {
private String stu_id;
public Student() {
super(); //Person构造函数
System.out.println("当前对象的简单名:"+this.getClass().getSimpleName());
System.out.println("当前对象的复杂名:"+this.getClass().getName());
}
}
Test类
package question;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
new Student();
}
}
测试结果:
当前对象的简单名:Student
当前对象的复杂名:question.Student
当前对象的简单名:Student
当前对象的复杂名:question.Student
第二个关于Object就不讲了!