my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Creation of Object without New & Construcotr Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creation of Object without New & Construcotr" Watch "Creation of Object without New & Construcotr" New topic
Author

Creation of Object without New & Construcotr

raghava rao
Greenhorn

Joined: Dec 03, 2004
Posts: 3
Hi All,
How to Instantiate a Class without NEW Operator and without using Constructor?

Thanks in Advance
Raghav
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
The newInstance() method of Class creates an object using the object's default constructor.


Mike Gershman
SCJP 1.4, SCWCD in process
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
You can't create an object without a call to some constructor, whether a default no-argument constructor or a user defined constructor.


42
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11480
    
  16

If you have a factory object, you won't ever SEE the call to a constructor...


Sure, the makeSportsCar method probably calls a constructor, or it calls a method that calls a constructor... but if i don't own the autoPlant class, and don't have access to it's source, i won't ever be able to see the constructor.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Creation of Object without New & Construcotr