先看代码执行结果:
import java.util.Date;
public class SuperClassTestDemo extends Date{
private static final long serialVersionUID = 890185079756933430L;
public static void main(String[] args) {
new SuperClassTestDemo().test();
}
public void test(){
System.out.println(super.getClass().getName());
System.out.println(this.getClass().getName());
System.out.println(getClass().getSuperclass().getName());
}
}
执行输出结果:
SuperClassTestDemo
SuperClassTestDemo
java.util.Date
解释:
测试getClass()方法,此方法为final修饰
public final Class<?> getClass():
Returns the runtime class of this Object. The returned Class object is the object that is locked by static synchronized methods of the represented class.