What is constructor in java?


Constructor is special methods whose name is same as class name. Constructor will be invoked by JVM.
            Constructors are mainly used to initialize the object. You can say constructors is the code that run when you say new on a class type.
For example
                        Hello h = new Hello();
Here Hello() is used as constructor not a method.
Constructors have no any return type. Constructor is called by JVM so it can’t be called explicitly.
Constructor can’t be inherited or overridden.
Construct can’t be static .

0 comments :

Post a Comment