1、RTTI:运行时识别一个对象的类型。
2、所有的类都是第一次使用时,动态加载到jvm中。当程序创建第一个对类的静态成员引用时,就会加载这个类。
3、Class对象仅在需要的时候才会被加载,static初始化是在类加载的时候进行的。
public interface A {
}
public interface B {
}
public interface C {
}
public class Totoy {
Totoy(){};
Totoy(int i){
}
}
public class Fanctoy extends Totoy implements A,B,C{
public Fanctoy(){
super(1);
}
public class Testtoy {
public static void main(String[] args) {
Class c = null;
try {
c = Class.forName("com.chen.fourteen.Fanctoy");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("can not find the fanctoy");
}
printf(c);
System.out.println("****************");
for(Class face:c.getInterfaces()){
printf(face);
}
Class up = c.getSuperclass();
Object obj = null;
try {
obj = up.newInstance();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
printf(obj.getClass());
}
static void printf(Class cc){
System.out.println("classname:"+cc.getName()+" is a interface "+cc.isInterface());
System.out.println("simplename:"+cc.getSimpleName());
System.out.println("cononicalname:"+cc.getCanonicalName());
}
}
4、类字面量常量:FancToy.class //简单安全高效
5、类的准备工作包括三个步骤:1、加载:类加载器查找字节码,创建一个class对象 2、链接:验证字节码,为静态域分配存储空间 3、初始化:执行静态方法或者静态块