Constructor
Constructor
What is Constructor?
A constructor in Java is a special method
that is used to initialize objects.
The constructor is called when an object of
a class is created.
Types
Default
Constructor
Parametrized Constructor
DEFAULT CONSTRUCTOR
TheDefault Constructor is a constructor that either
has no parameters, or if it it has parameters all
parameters have default values. If there is no
Constructor in a class, Compiler automatically
creates a Default Constructor
Default Constructor
class Test
{
Test() //Default Constructor
{
System.out.println(“Default Constructor is Invoked”);
}
}
PARAMETRIZED CONSTRUCTOR