This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

constructor

 
kri shan
Ranch Hand
Posts: 1473
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between creating the object within the constructor and outside the constructor?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand the question, do you have some code you can give as an example?
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A constructor doesn't really create an object, it completes the initialization of the object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic