Using ClassLoader to load and create instance of class

ClassLoaderDemo.java

class A implements Runnable{ public void run(){ for(int i=0;i<10;i++){ try{Thread.sleep(500);}catch(Exception e){} System.out.println(i+" A"); } } } class ThreadDemo1 { public static void main(String ar[])throws Exception{ A a1; Class c=Class.forName("A"); a1=(A)c.newInstance(); Thread t1=new Thread(a1); t1.start(); System.out.println("Finished"); } }

No comments:

Popular Posts