Declaration vs Instantiation vs Initialization

Declaration, Instantiation and Initialization are very confusing terms in Java. Let us clear their meanings with example :

Declaration

A variable is said to be declared when we give name to variable and associate it with a class.

Example :- Student stu; (here Student is a class)

Instantiation

Instantiation means we are creating an object or allocating memory. So use of new keyword to create an object and allocate memory is instantiation.

Initialization

Initialize means we are associating/assigning some values to an object. So to associate values with object we call constructor. So calling constructor is called initialization.

Example:- new Student(); (here we are instantiating object using new keyword and initializing object by calling constructor).

0

Ankit

Ankit is a computer adventurer who loves to explore different things related to technology. He has been associated with technology and coding from past 10 years.

View all posts by Ankit →

Leave a Reply

Your email address will not be published. Required fields are marked *