/* Listing4301.java */ import java.io.*; interface HelloMeth { public void hello(); } class CA implements HelloMeth { public void hello() { System.out.println("hello CA"); } } class CB implements HelloMeth { public void hello() { System.out.println("hello CB"); } } class CC { public void hello() { System.out.println("hello CC"); } } class CD { public void hallo() { System.out.println("hallo CD"); } } public class Listing4301 { public static void main(String[] args) { String buf = ""; BufferedReader in = new BufferedReader( new InputStreamReader( new DataInputStream(System.in))); while (true) { try { System.out.print("Klassenname oder ende eingeben: "); buf = in.readLine(); if (buf.equals("ende")) { break; } Class c = Class.forName(buf); Object o = c.newInstance(); ((HelloMeth)o).hello(); } catch (IOException e) { System.out.println(e.toString()); } catch (ClassNotFoundException e) { System.out.println("Klasse nicht gefunden"); } catch (ClassCastException e) { System.out.println(e.toString()); } catch (InstantiationException e) { System.out.println(e.toString()); } catch (IllegalAccessException e) { System.out.println(e.toString()); } } } }