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

Popular posts from this blog

Mastering String Manipulation in Java

Getting Started with Design Patterns - Part 1

Angular Beginner's Guide - Part 1