- package com.itheima;
- public class Test {
- public static void main(String[] args) {
- Person p1 = new Person();
- Class c1 = Person.class;
- Class c2 = p1.getClass();
- Class c3 = null;
- try {
- // =================问题区=======================
- c3 = Class.forName("test.Person");
- /*
- * 为什么这个地方写上test.Person后c2==c3就返回true;而写上Person后c2==c3就返回false
- */
- // =================问题区=======================
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println(c2 == c3);
- }
- }
- class Person {
- String name = "shuiguo";
- public String getName() {
- return name;
- }
- }
复制代码
|
|