Java反射机制之动态加载

Java反射机制之动态加载_第1张图片

public interface OfficeAble{
	public void start();
}

public class Excel implements OfficeAble {
	public void start(){
		System.out.println("excel run...");
	}
}

public class Word implements OfficeAble {
	public void start(){
		System.out.println("word run...");
	}
}

public class OfficeBetter {
	public static void main(String[] args) {
		try{
			Class c1 = Class.forName(args[0]);
			OfficeAble oa = (OfficeAble)c1.newInstance();
			oa.start();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}



你可能感兴趣的:(Java)