8th Day @ Apex: Constructors

Hi Readers!
I will share the concept of Constructor in Java today which I have learnt today.

Constructors in Java:
Constructors are used to initializing the object’s state. Like methods, a constructor also contains a collection of statements(i.e. instructions) that are executed at the time of Object creation.

When is a Constructor called?
Each time an object is created using new() keyword at least one constructor (it could be default constructor) is invoked to assign initial values to the data members of the same class.

Image result for constructor in java

There is two type of constructor in Java:

No-argument constructor: A constructor that has no parameter is known as default constructor. If we don’t define a constructor in a class, the compiler creates a default constructor(with no arguments) for the class. And if we write a constructor with arguments or no-argument then the compiler does not create a default constructor.
Default constructor provides the default values to the object like 0, null etc. depending on the type.

Comments

Popular posts from this blog

How to add Internet download manager extension in the Chrome browser

A Day in Noida: Learning Begins

Python Deciding factor