wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "constructor" Watch "constructor" New topic
Author

constructor

kri shan
Ranch Hand

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

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
 
wood burning stoves
 
subject: constructor
 
Similar Threads
main method
WA #1.....word association
Constructor doubt - K&B Book
Can I overload a constructor with enum values?
IS CONCTRUCTOR IS A METHOD