Choose Skin

What is constructor?

Answered by Manish Kumar 

Constructor is a block of code that allows you to create an object of class. This can also be called creating an instance. Constructor looks like a method but it’s not, for example methods can have any return type or no return type (considered as void) but constructors don’t have any return type not even void. There are basically two rules defined for the constructor. 1. Constructor name must be same as its class name 2. Constructor must have no explicit return type There are two types of constructors: 1. Default constructor (no-arg constructor) 2. Parameterized constructor

  Refine your Search