[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
Re: Java CreateObject
the thing u want is explained below with an example
public class ClassDemo2 {
public static void main(String args[]) {
Class cls = null;
Object obj = null;
// load a class by name
try {
cls = Class.forName(args[0]);
}
catch (ClassNotFoundException exc) {
System.err.println(exc);
}
// create a new instance of that class
try {
obj = cls.newInstance();
}
catch (IllegalAccessException exc1) {
System.err.println(exc1);
}
catch (InstantiationException exc2) {
System.err.println(exc2);
}
}
}
for more info http://developer.java.sun.com/developer/TechTips/2000/tt0314.html.
___________
Deepak
At 6/25/00 7:52:00 PM, you wrote:
>I want to create java objects with their class names known at runtime. I
>want something of this:
> objref = createobject("classname");
>I will not be able to use : Classname Obj = new Classname() ; Will
>interfaces be useful for this?
>------------------
>Lakshmi Anand K
>MSPV Group
>Pavoorchatram
>
>
>-----------------------------------------------------------------------
>For information on this and other Linux India mailing lists check out
>http://lists.linux-india.org/
>
>
-----------------------------
deepak
have a great day
ICQ 30662394