1There are three types of constructors:
2Default, No-arg constructor and Parameterized.
3
4If you do not implement any constructor in your class,
5Java compiler inserts a default constructor into your code on your behalf.
6This constructor is known as default constructor.
7
8Constructor with no arguments is known as no-arg constructor
9
10Constructor with arguments(or you can say parameters) is known as
11Parameterized constructor.
1class Other{
2 public Other(String message){
3 System.out.println(message);
4 }
5}
6
7class scratch{
8 public static void main(String[] args) {
9 Other method = new Other("Hey");
10 //prints Hey to the console
11 }
12}
1A constructor is a special method used to initialize objects in java.
2we use constructors to initialize all variables in the class
3when an object is created. As and when an object
4is created it is initialized automatically with the help of
5constructor in java.
6
7We have two types of constructors:
8Default Constructor
9Parameterized Constructor
10
11public classname(){
12}
13public classname(parameters list){
14}
1A constructor is a special method
2used to initialize objects in java.
3we use constructors to initialize
4all variables in the class
5when an object is created.
6 As and when an object
7is created it is initialized
8automatically with the help of
9constructor in java.
10
11We have two types of constructors:
12Default Constructor
13Parameterized Constructor
14
15I use Constructor in pages classes in my framework
16public classname(){
17}
18public classname(parameters list){
19}
20
21