Some points to remember when writing constructors
- The constructor name and class name must be same.
- Constructor may or may not have parameters.
- A constructor does not return any value not even void.
- Constructor is called only once at the time of creating the objects.
- A constructor with out any parameter is called default constructor.
- A constructor with one or more parameters is called parameterized constructor.
- Default constructors are stored the same data in all objects.
- Parameterized Constructor is used with initialize the object with default data.
- Writing two or more constructors with the same name but difference in the parameters is called constructor overloading.
NOTE:
When no constructor written in the class when java compiler act’s default constructor with default values.
No comments:
Post a Comment