|
|
Constructors can be used to initialize member variables, whenever your
program creates a class object.
Each constructor is named for the class in which it is defined. Constructors
do not have a return-value data type.
The default constructor has no parameters. You should include a definition
of a default constructor in every class that you define.
If you wish to use the default constructor to initialize a class object's
member variable values, then use the declaration form:
ClassName VariableName ;
String str;// Not String str ();
Member functions in general, and constructors, readers and writers in
particular, have complete access to all member variables, public and private.
The public-private separation helps ensure that you can benefit from data
abstraction.
|
|