Java Constructor Interview Question1
What is constructor in java?
A Constructor is a block of code with same name as that of the class and it looks similar to a method. But method and constructor are separate and two distinct concepts. A method is declared with return type whereas for constructor we do not provide any return type at all.
Every time you create an object (mostly using new keyword) in java, a constructor is invoked which helps in initializing the object.
If you do not create a constructor yourself then you will be provided with a default constructor in java.
Can constructor be overloaded?
Yes, we can overload constructors in java.
Can constructor be inherited?
No, constructor cannot be inherited.
Can constructor be overridden?
No, constructor cannot be overridden.
Does constructor return anything?
Yes, constructor returns the instance of the class.