1 Packagetest;2 Importjava.util.Date;3 Public classSuperTestextendsdate{4 Private Static Final LongSerialversionuid = 1L; 5 Private voidTest () {6System.out.println (Super. GetClass (). GetName ()); 7 } 8 9 Public Static voidMain (String[]args) {Ten NewSuperTest (). Test (); One } A}
The output is: test. SuperTest
Analysis:super
.getClass() 得到的依然是runtime当前类,若要得到真正的父类,需要用
super
.getClass().getSuperclass()
虽然这里写的是
super
,但其实用
this
也一样
The class class of Java is the basis of the Java reflection mechanism, and we can obtain information about a class through class classes. Java.lang.Class is a special class that encapsulates information that is loaded into a class (including classes and interfaces) in the JVM. When a class or interface is loaded into the JVM, it produces a Java.lang.Class object associated with it, which can be accessed through this class object for the details of the loaded class.
The class class for Java