forked from JustinSDK/JavaSE6Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForNameDemo.java
More file actions
24 lines (23 loc) · 895 Bytes
/
ForNameDemo.java
File metadata and controls
24 lines (23 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package onlyfun.caterpillar;
public class ForNameDemo {
public static void main(String[] args) {
try {
Class c = Class.forName(args[0]);
System.out.println("類別名稱:" +
c.getName());
System.out.println("是否為介面:" +
c.isInterface());
System.out.println("是否為基本型態:" +
c.isPrimitive());
System.out.println("是否為陣列:" + c.isArray());
System.out.println("父類別:" +
c.getSuperclass().getName());
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println("沒有指定類別名稱");
}
catch(ClassNotFoundException e) {
System.out.println("找不到指定的類別");
}
}
}