aspose file tools*
The moose likes Java in General and the fly likes Object Creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Object Creation " Watch "Object Creation " New topic
Author

Object Creation

siva prakash
Ranch Hand

Joined: Aug 24, 2004
Posts: 80
Hi All,

i am going thru specification of java, and i found we can also create an instance of class using Class.forName(class_name).newInstance()

what advantage we can get using this approach instead of normal approach.

pls clarify me


With regards,
siva
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
with this way, you don't have to know the class name at compile time. see also the reflection tutorial for more information.
William A White
Ranch Hand

Joined: Jul 01, 2004
Posts: 35
If you don't know what kind of object you want to create, this code lets you decide at run time.

You'd usually make use of it in conjunction with reflection, or some kind of factory that made different objects.
 
 
subject: Object Creation