Share this post! | Vote this! |
|
A constructor is a special method that is created when the object is
created or defined. This particular method holds the same name as that
of the object and it initializes the instance of the object whenever
that object is created. The constructor also usually holds the
initializations of the different declared member variables of its
object. Unlike some of the other methods, the constructor does not
return a value, not even void.
When you create an object, if you do not declare a constructor, the compiler would create one for your program; this is useful because it lets all other objects and functions of the program know that this object exists. This compiler created constructor is called the default constructor. If you want to declare your own constructor, simply add a method with the same name as the object in the public section of the object. When you declare an instance of an object, whether you use that object or not, a constructor for the object is created and signals itself. more...
FURTHER READING
When you create an object, if you do not declare a constructor, the compiler would create one for your program; this is useful because it lets all other objects and functions of the program know that this object exists. This compiler created constructor is called the default constructor. If you want to declare your own constructor, simply add a method with the same name as the object in the public section of the object. When you declare an instance of an object, whether you use that object or not, a constructor for the object is created and signals itself. more...
FURTHER READING
0 comments:
Post a Comment