Constructor in java 1

Constructors When you create a new instance (a new object) of a class using the new keyword, a constructor for that class is called. Constructors are used to initialize the instance variables (fields) of an object. Constructors are similar to methods, but with some important differences. Constructor name is class name. A constructors must have the same name as the class its in. Default constructor. If you don’t define a constructor for a class, a default parameterless constructor is automatically created by the compiler. [Read More]

Types of constructors

1. Void constructors or default constructors This has no parameters and is must in case of dynamic allocation of objects. 2. Default parameter constructor A default parameter is a function parameter that has a default value provided to it. If the user does not supply a value for this parameter, the default value will be used. If the user does supply a value for the default parameter, the user-supplied value is used. [Read More]