Results 1 to 2 of 2
  1. #1
    ajaygargnsit is offline Member
    Join Date
    Dec 2007
    Posts
    9
    Rep Power
    0

    Default '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

  2. #2
    Join Date
    Dec 2007
    Posts
    24
    Rep Power
    0

Similar Threads

  1. Casting an int value into a char
    By kurtulas in forum New To Java
    Replies: 2
    Last Post: 02-16-2008, 09:03 PM
  2. Type Casting Help
    By rhm54 in forum New To Java
    Replies: 2
    Last Post: 02-07-2008, 01:06 PM
  3. 'Casting' couch !!!!
    By ajaygargnsit in forum Advanced Java
    Replies: 4
    Last Post: 01-04-2008, 05:54 PM
  4. Casting
    By leebee in forum New To Java
    Replies: 5
    Last Post: 08-10-2007, 01:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •