Class类
![class类](https://i-blog.csdnimg.cn/blog_migrate/99dbf335864d54d208b8c899b909ebcc.png)
Class类的常用方法
![class类的方法](https://i-blog.csdnimg.cn/blog_migrate/50566cebc39fadbaa868ba735ea86e0f.png)
获取Class 类的实例
![获取Class类的实例](https://i-blog.csdnimg.cn/blog_migrate/c47337ff2341ca557191d634930a4285.png)
package com.kuang.reflection;
public class Test03 {
public static void main(String[] args) throws ClassNotFoundException {
Person person = new Student();
System.out.println("这个人是"+person.name);
Class c1 = person.getClass();
System.out.println(c1.hashCode());
Class c2 = Class.forName("com.kuang.reflection.Student");
System.out.println(c2.hashCode());
Class c3 = Student.class;
System.out.println(c3.hashCode());
Class c4 = Integer.TYPE;
System.out.println(c4);
Class c5 = c1.getSuperclass();
System.out.println(c5);
}
}
class Person{
public String name;
public Person() {
}
public Person(String name) {
this.name = name;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
'}';
}
}
class Student extends Person{
public Student(){
this.name = "学生";
}
}class Teacher extends Person{
public Teacher(){
this.name = "老师";
}
}
![运行结果](https://i-blog.csdnimg.cn/blog_migrate/b0e9e68abeef7ff70a68a4e8cc9910c2.png)