System.out.println("1、通过类本身获得对象");
20 Class clazz = this.getClass();
21 System.out.println(clazz.getName());
22 System.out.println("==============");
23
24 System.out.println("2、通过子类的实例获得父类对象");
25 Customer customer = new Customer();
26 clazz = customer.getClass();
27 System.out.println(clazz.getSuperclass().getName());
28 System.out.println("==============");
29
30 System.out.println("3、通过类名.class获取对象");
31 Class forClass = com.ljq.test.GetClassTest.class;
32 System.out.println(forClass.getName());
33 System.out.println("==============");
34
35 System.out.println("4、通过类名的字符串获取对象");
36 Class forName = Class.forName("com.ljq.test.GetClassTest");
37 System.out.println(forName.getName());
38 System.out.println("=============");
20 Class clazz = this.getClass();
21 System.out.println(clazz.getName());
22 System.out.println("==============");
23
24 System.out.println("2、通过子类的实例获得父类对象");
25 Customer customer = new Customer();
26 clazz = customer.getClass();
27 System.out.println(clazz.getSuperclass().getName());
28 System.out.println("==============");
29
30 System.out.println("3、通过类名.class获取对象");
31 Class forClass = com.ljq.test.GetClassTest.class;
32 System.out.println(forClass.getName());
33 System.out.println("==============");
34
35 System.out.println("4、通过类名的字符串获取对象");
36 Class forName = Class.forName("com.ljq.test.GetClassTest");
37 System.out.println(forName.getName());
38 System.out.println("=============");