*A constructor is a method in a class named similarly to the class.
which is executed when we create an instance of the class.
*
NOTE -
- No return type (not even void)
- It doesn't return anything.
- This makes it different from other methods.
- To initialize class fields(variables) or properties when an object is created means assigning a value to the variables.
Points -
- 1. Automatically invoked or called when we use the 'new' keyword.
Student s = new Student();
- You can have multiple constructors in a class with different parameters(Constructor Overloading).
- A constructor with no parameters is called the default constructor
- If we not create a manually constructor, then the compiler provides/initialize implicit constructor.
Top comments (0)