Use of constructors

Reply

Join Date: May 2007
Posts: 16
Reputation: tinamary is an unknown quantity at this point 
Solved Threads: 0
tinamary tinamary is offline Offline
Newbie Poster

Use of constructors

 
0
  #1
Oct 19th, 2007
what is the use of constructors in java when we can intialize objects directly
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,346
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 498
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Use of constructors

 
0
  #2
Oct 19th, 2007
Can you elaborate a little more on the question? All object creation is done through constructors. If no constructor is specified, the compiler will supply a default empty constructor that basically does nothing. If you wish to provide info that initializes some values in the object when it's created, you provide a constructor for those parameters and initialize those values in that constructor.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,118
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 471
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: Use of constructors

 
0
  #3
Oct 19th, 2007
Do you think that user of your application will be interested in reading your code and seting all variables by him self? Or do you think all variables are always initialized?
Last edited by peter_budo; Oct 19th, 2007 at 12:08 pm.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC