| | |
what is the effect of using constructors in the program?
![]() |
•
•
Join Date: Mar 2004
Posts: 762
Reputation:
Solved Threads: 38
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");
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");
•
•
•
•
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");
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.
•
•
Join Date: Mar 2004
Posts: 762
Reputation:
Solved Threads: 38
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.
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.
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.
![]() |
Similar Threads
- Insufficient Contextual Information to determine type (C++)
- Program 'Sample' not responding (Viruses, Spyware and other Nasties)
- Lat/Long to binary (Computer Science)
- prime numbers homework trouble (C++)
Other Threads in the Java Forum
- Previous Thread: Loading images
- Next Thread: Help on error message, illegal start an ';' expected
| Thread Tools | Search this Thread |
addball android api applet application apps array automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse ee error eventlistener exception expand fractal free game gis givemetehcodez graphics gui guidancer html ide image integration intellij j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia jvm linux loop map method migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle phone physics plazmic print problem program programming project radio scanner server service set sharepoint smart sms smsspam software sortedmaps sql subclass support swing textfield threads tree trolltech unlimited utility windows






