Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-20-2007, 11:39 AM
Member
 
Join Date: Dec 2007
Posts: 9
ajaygargnsit is on a distinguished road
'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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-22-2007, 03:05 PM
khamuruddeen's Avatar
Member
 
Join Date: Dec 2007
Posts: 24
khamuruddeen is on a distinguished road
mention that one as

i i_obj=(i)new C1();
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Casting an int value into a char kurtulas New To Java 2 02-16-2008 10:03 PM
Type Casting Help rhm54 New To Java 2 02-07-2008 02:06 PM
'Casting' couch !!!! ajaygargnsit Advanced Java 4 01-04-2008 06:54 PM
Casting leebee New To Java 5 08-10-2007 02:24 PM


All times are GMT +3. The time now is 01:39 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org