Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

constructor

 
kri shan
Ranch Hand
Posts: 1467
  • 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