Constructor

--

Constructor is a special method/special member of the class which is used to initialize the data members(variables & methods).

Key Points of Constructor:

  1. Constructor name should be same as class name.
  2. It will not have return type.
  3. It will not return any value.
  4. It is always non static.
  5. Whenever you create an object, constructor will be invoked.

Syntax:

className(){

}

Constructors are of two types:

  1. Non Parameterized Constructor.
  2. Parameterized Constructor.

--

--

Sri Priya P Kulkarni
Sri Priya P Kulkarni

Written by Sri Priya P Kulkarni

SDET| Blogger! | Automation Enthusiast! | On a journey of Continuous learning.... !

Responses (1)