Package com.imooc.test;
public class ClassDemo1 {
public static void Main (string[] args) {
Foo fool = new Foo ();//foo1.
Foo This class is also an instance object, the Class class instance object, how to express it
Any class is an instance object of class, and this instance object is represented in three ways
The first representation---> actually tells us that any class has an implied static member variable class
Class cl = Foo.class;
The second expression, known to the class of objects through the GetClass method
Class C2 = Fool.getclass ();
*/* The website explains that C1,C2 represents the class type of the Foo class (class type)
* Everything is the object of everything
* Class is also an object, an instance object of class
* This object we call the class type of the class
*/
Whether C1 or C2 represent the class type of the Foo class, a class can only be an instance object of class
System.out.println (cl = = C2);
The third way of expression
Class C3 = null;
try {
C3 = Class.forName ("Com.imooc.test.Foo");
} catch (ClassNotFoundException e) {
E.printstacktrace ();
}
System.out.println (C2 = = C3);
We can create an instance of this class from the class type of the class, and create instances of Foo through C1.C2.C3.
try {
Foo foo = (foo) cl.newinstance ();//premise requires the construction method without parameters
Foo.print ();
} catch (Instantiationexception e) {
E.printstacktrace ();
} catch (Illegalaccessexception e) {
E.printstacktrace ();
}
}
}
Class foo{
void print () {
System.out.println ("foo print output");
}
}
The use of Java reflection for the interpretation of class classes