Why use a constructor. I'm pretty sure I understand how they work but it's still pretty "fuzzy". I just don't understand their primary function I guess. Can someone please help clear this up? Thank you!
Constructors complete the initialization of new objects. They often accept arguments to use in the initialization. They can pass information to an object's superclass to initialize the superclass first.
Check out a few classes like String and Integer in Sun's API documentation and you'll see how they are used.
I think the primary function of a constructor would be to initilaize some parameters for an object before it is used. For example in a database object constructor we may define the database connection parameters, before using the database object.
//Example of public DatabaseConstructor(){ Connection conn=getDatabaseConnection(); Statement stmt=null; ResultSet rs=null; }