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 constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "constructor" Watch "constructor" New topic


kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1428
What is the difference between creating the object within the constructor and outside the constructor?
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

I'm not sure I understand the question, do you have some code you can give as an example?
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
I dont feel there is any difference between creating the objects inside & outside a constructor.
Normally when ever a object is created the corresponding constructor or atleast a default constructor is called.

If a class extends from some other class and when ever a object of the child is created, the constructor in the child class automatically invokes the default constructor in the super class & this goes till the top level heirarchy of class.

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
A constructor doesn't really create an object, it completes the initialization of the object.

Mike Gershman
SCJP 1.4, SCWCD in process
I agree. Here's the link:
subject: constructor
It's not a secret anymore!