class mainClass
{
public static void main(String[] args)
{
System.out.println(args[0]);
try{
ISay obj=(ISay)Class.forName(args[0]).newInstance();
obj.say();
}
catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public interface ISay
{
void say();
}
class SayHello implements ISay
{
public void say()
{
System.out.println("Hello!");
}
}
class SayBye implements ISay
{
public void say()
{
System.out.println("Bye!");
}
}
标签:forName,obj,void,args,say,ISay,catch,public
From: https://blog.51cto.com/gjwrxz/6322972