File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Creation of Object without New & Construcotr

raghava rao

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

Thanks in Advance
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.

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

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
I agree. Here's the link:
subject: Creation of Object without New & Construcotr
jQuery in Action, 3rd edition