what is the effect of using constructors in the program?

Reply

Join Date: Sep 2004
Posts: 18
Reputation: psylocke is an unknown quantity at this point 
Solved Threads: 0
psylocke psylocke is offline Offline
Newbie Poster

what is the effect of using constructors in the program?

 
0
  #1
Nov 9th, 2004
i dont know exactly why constructors are being used, it is used in what purpose?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,579
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 709
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: what is the effect of using constructors in the program?

 
0
  #2
Nov 9th, 2004
>i dont know exactly why constructors are being used
Not using a constructor is akin to a restaurant giving you a glass without the drink. In the simplest manner, constructors guarantee that your object is created with predictable data for the methods to work with.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 763
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: what is the effect of using constructors in the program?

 
0
  #3
Nov 9th, 2004
sounds like he hasn't covered objects yet in class. Here's an example where a constructor takes in 1 string.

MyClass person = new MyClass("name");

The object "person" now has an attribute already set to that string. Without a constructor, you would have to do this:

MyClass person = new MyClass();
person.setName("name");
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,579
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 709
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: what is the effect of using constructors in the program?

 
0
  #4
Nov 9th, 2004
Originally Posted by Phaelax
sounds like he hasn't covered objects yet in class. Here's an example where a constructor takes in 1 string.

MyClass person = new MyClass("name");

The object "person" now has an attribute already set to that string. Without a constructor, you would have to do this:

MyClass person = new MyClass();
person.setName("name");
>sounds like he hasn't covered objects yet
Right. So giving an example that uses objects, constructors, new, methods, and arguments, and fails to explain what's meant by object, string, and attribute is soooo informative. :rolleyes:
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 763
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: what is the effect of using constructors in the program?

 
0
  #5
Nov 10th, 2004
oops:cheesy:

when i learned about objects, i was told what they were but never understood it until i saw code, but thats just how i learn. seeing code and figuring it out rather than listening to what it is. I wrote a document awhile ago about what objects are and how to get started with java programming using BlueJ. The article's website isn't online anymore, but I can try to locate it later for you.
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 1,749
Reputation: nanosani is an unknown quantity at this point 
Solved Threads: 55
Team Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: what is the effect of using constructors in the program?

 
0
  #6
Nov 10th, 2004
Constructors simply initialize your program ... intialize means that what do you want your program to do automatically when it starts ... for example if you make a GUI (Graphical User Interface) you'll want your program to display the window and all the buttons and fields etc when the program starts ... so you'll write all these in your constructor.
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC