1: Obtained through the method getclass that each object has. Cons: You must create the class object before you can call the GetClass method.
2: Each data type (basic data type and reference data type) has a static property class. Cons: This class must be identified first.
The first two methods are not conducive to the extension of the program, because it is necessary to use a specific class to complete the program.
3: The method used in class, the static Forname method .
Specifies what class name to get what class bytecode file object, this way is strongest, as long as the class name of the string passed in.
//1. obtained for class loading based on the given class name
String classname = "Cn.itcast.reflect.Person";//From configuration file
Class clazz = class.forname (classname);//This object represents Person.class
//2. If you get the object, don't know what type is used to get the object type
Object obj = new person ();
Class clazz1 = Obj.getclass ();//Get the object specific type
//3. If you are explicitly getting a class object that is used primarily to pass a reference
Class clazz2 = Person.class;
Three ways to get a class object