The class object is generated in the following way:
1.class.forname ("Class name string") (Note: Class name string must be full name, package name + class name)
2. Class name.
3. Instance object. GetClass ()
- Class testtypeforname=class.forname ("Testclasstype");
- System.out.println ("Testforname---" +testtypeforname);
- Test class name. class
- Class Testtypeclass=testclasstype. class;
- System.out.println ("Testtypeclass---" +testtypeclass);
- Test Object.getclass ()
- Testclasstype testgetclass= New Testclasstype ();
- System.out.println ("Testgetclass---" +testgetclass.getclass ());
Static Method property initialization is initialized when the class is loaded. Instead of static method property initialization, it is loaded at the time of the new class instance object.
Therefore, this procedure shows that three ways to generate a class object, in fact, there is only one class object. When generating a class object, first determine if the memory is loaded.
So, the process of generating a class object is actually the same:
When we write a new Java class, the JVM will compile it into a class object, stored in a. class file of the same name. At run time, when the object of this class needs to be generated, the JVM checks to see if the class is already loaded in memory. If it is not loaded, the. class file is loaded into memory. If loaded, the instance object is generated according to the class file.
Java--class Object