001package edu.pdx.cs410J.reflect;
002
003/**
004 * This program reads the name of a class with a zero-argument
005 * constructor and uses Java reflection to load and instantiate the
006 * class.
007 */
008public class InstantiateClass {
009
010  public static void main(String[] args) {
011    ClassLoader cl = ClassLoader.getSystemClassLoader();
012    try {
013      Class c = cl.loadClass(args[0]); 
014      Object o = c.newInstance();
015      System.out.println(o);
016
017    } catch (InstantiationException ex) {
018      String s = "Could not instantiate " + args[0];
019      System.err.println(s);
020
021    } catch (IllegalAccessException ex) {
022      String s = "No public constructor for " + args[0];
023      System.err.println(s);
024
025    } catch (ClassNotFoundException ex) {
026      String s = "Could not find " + args[0];
027      System.err.println(s);
028    }
029  }
030
031}