生活随笔
收集整理的這篇文章主要介紹了
Java-得到 Class 类的几种方式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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("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
;}@Overridepublic String
toString() {return "Person{" +"name='" + name
+ '\'' +'}';}
}class Student extends Person{public Student(){this.name
= "學生";}
}class Teacher extends Person{public Teacher() {this.name
= "老師";}
}
https://www.bilibili.com/video/BV1p4411P7V3?p=7
總結
以上是生活随笔為你收集整理的Java-得到 Class 类的几种方式的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。