目录结构
lee-Macbook-Air:java-learn lee$ tree reflect/
reflect/
├── Excel.class
├── Excel.java
├── Office.class
├── Office.java
├── OfficeAble.class
├── OfficeAble.java
├── Word.class
└── Word.java
0 directories, 10 files
class Office {
public static void main(String[] args) {
try {
Class c = Class.forName(args[0]);
OfficeAble oa = (OfficeAble)c.newInstance();
oa.start();
} catch(Exception e) {
e.printStackTrace();
}
}
}
interface OfficeAble {
public void start();
}
class Word implements OfficeAble {
public void start() {
System.out.println("Word start..");
}
}
class Excel implements OfficeAble {
public void start() {
System.out.println("Excel start");
}
}