一
package com.eoms;
public interface TestInterface {
public String doAction(String name);
}
二
package com.eoms;
public class IActionImp implements TestInterface{
public String doAction(String name) {
return name;
}
}
三
package com.eoms;
public class DotestAction {
public String testClass()
{
String restult = "";
String testa = "com.eoms.IActionImp";
try{
Object obj = Class.forName(testa).newInstance();
TestInterface testInterface = (TestInterface) obj;
restult=testInterface.doAction("Succed");
}catch(Exception ex){
ex.printStackTrace();
}
return restult;
}
public static void main(String args[])
{
DotestAction doaction = new DotestAction();
String result = doaction.testClass();
System.out.println("测试结果: "+result);
}
}
打印:
测试结果: Succed