|
'Casting' couch !!!!
Well, what I need to do this.
I have designed an interface; and two classes c1 and c2 that implement this interface. Now, I need to create an object of one of the classes (dynamically), but assign it as an interface instantiation. That is,
interface i
{
void f1();
void f2();
}
class c1 implements i
{
void f1(){}
void f2(){}
}
class c2 implements i
{
void f1(){}
void f2(){}
}
Now, I know the following will work ::
i i_obj = new c1();
i i_obj = new c2(); // Fine till here !!!!!!!!!!!!!!!!!!!
But suppose I now want to the same thing, but the 'class type' must be known at run time, through the 'Properties class' object, by making use of Class.forname() function.
NOW, how do i proceed ??
Looking forward to reply.
Ajay Garg
|