Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creation of Object without New & Construcotr

 
raghava rao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
How to Instantiate a Class without NEW Operator and without using Constructor?

Thanks in Advance
Raghav
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The newInstance() method of Class creates an object using the object's default constructor.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 12122
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic