Exploring the Power of Constructors
Exploring the Power of Constructors
A constructor is a special method that is used to initialize objects. Constructor is automatically called when an object of that class is created. The constructor name same as the class name and they do not have a return type.
Type of Constructors 👇
Parameterless 📌
🌟A parameterless constructor, often referred to as a default constructor, is a constructor in a class that takes no parameters.
🌟It is called
automatically when an object of the class is instantiated without passing any
arguments.
Parameterized📌
🌟A parameterized constructor is a constructor in a class that takes one or more parameters.
🌟It allows you to initialize the object with specific values at the time of its creation.
🌟A parameterized constructor expects one or more arguments when it is called.
🌟The parameter list of the constructor
works as parameter list and the parameter list of the object becomes an argument
list.
Article by-:
Rasanjali Herath
E-Mail-:
rasanjaliherath899@gmail.com
Comments
Post a Comment