Constructor in Java
Constructor: 1. It is used to initialize an object. 2. It is open type of special method. 3. It is used to provide values for the "instance" variables. 4. Constructor is invoked implicitly. 5. The java compiler provides a default constructor if you don't have any Constructor. Rules: 1. Constructor should be having same name as class name. 2. It should not having any return type. Syntax: <Access Modifier><class name>() Two types of constructor: 1. Default Constructor: Constructor which has no parameters,known as Default Constructor. 2. Parameterized Constructor : Constructor which has a parameters, known as Parameterized constructor. Constructor will be called simultaneously whenever we are creating an object. Keypoints in Java Constructor: 1. We are supposed to initialize an object with the available constructor present in the class. 2. If we are trying to initialize ...