i dont know exactly why constructors are being used, it is used in what purpose?
psylocke 0 Newbie Poster
Recommended Answers
Jump to Post— Narue 5,707>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.
Jump to Post— Phaelax 52sounds 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 …
All 5 Replies
Narue 5,707 Bad Cop Team Colleague
Phaelax 52 Practically a Posting Shark
Narue 5,707 Bad Cop Team Colleague
Phaelax 52 Practically a Posting Shark
nanosani 20 Technize.net addict Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.