Java Basic Tutorial
Java Advance Tutorial
A constructor in Java is a special method used to initialize objects. It is called when an object of a class is created and is used to assign initial values to the instance variables of the class. The name of the constructor is the same as the class name, and it does not have a return type (not even void
).
Default Constructor
Try it yourself
Parameterized Constructor
Try it yourself
You can define multiple constructors in a class with different parameter lists.
Try it yourself