In an object-oriented world, everything is object.
1) whose object is the class?
A class is an object, and a class is an instance object of the Java.lang.Class class.
2) How is this object represented?
PackageCom.reflect; Public classClassDemo1 { Public Static voidMain (string[] args) {//how Foo objects are representedFoo foo1=NewFoo ();//f001, that's it.//Foo This class, is also a total instance object, the Class class instance object, how to express it? //any total class is an instance object of class, and this instance object is represented in three ways//The first representation--"actually tells us that any total class has an implied static member variable class Class C1=foo.class; //The second expression is known to the object of the class, through the GetClass methodClass c2=Foo1.getclass (); //Official website C1,C2 indicates the class type of the Foo class ( class type)//Everything is Object,//class is also an object, an instance object of class//This object we call class type of class//whether C1 or C2 represent the class type of the Foo class, the total class can only be a total instance object of classSystem.out.println (c1==C2); //The Third Way of expressionClass c3=NULL; Try{C3=class.forname ("Com.reflect.Foo"); } Catch(ClassNotFoundException e) {e.printstacktrace (); } System.out.println (C2==C3); //We can create instance objects of the class--> by the class type of the class, by creating an instance of Foo by C1 or C2 or C3. Try{Foo Foo2= (Foo) c1.newinstance ();//need to have a parameterless construction methodFoo2.print (); } Catch(instantiationexception e) {e.printstacktrace (); } Catch(illegalaccessexception e) {e.printstacktrace (); } }}classfoo{voidprint () {}}
Java Reflection--class Class