Java | What Is The Difference Between Variable, Object, And Reference?

In This Tutorial we will Discuss Java | What Is The Difference Between Variable, Object, And Reference? A variable is used for storing the data, Objects are the instant of class, and reference types points toward the object stored in the heap area and store the address.


What Is Variable In Java?

Variables are some places just like a box where we store the data that is our information and that variable is being stored in memory.
Let’s understand with the help of an example.


As we can see age is a variable that is just like a box and it is holding a value that is 21 so we can conclude as variables are the place where we store our values. Variable is being initialized with some specification of data type means we have to specify in java what type of data that variable is going to store.

For example


What Is Objects?

Objects are said as the instant of class or we can say it is declared the same as a variable with the data type of class means as we initialize a variable with some data type similarly we initialize the object with the class as data type.

to understand objects in a simpler way we can say objects are used for calling the member function of any class and we can not access non-static functions of any class.

Sor For example

public class Student {
   String name " Prakhar";
   int age = 20;
   void greet() {
      System.out.println("Hello how are you");
public class Example {
   public static void main(String args[]) {
      Student obj = new Student();

Here obj is an object of the Student class to access the function of the student class we need to create the object.


What Is Reference

As we know objects are created in the heap area and references are used to point to the memory location or heap area where the object is created.



Learn More about What Is The Difference Between Variable, Object, And Reference? at: Variable, Objects and reference

And Also Visit JAVA TUTORIALS To learn More about java and solve your problems faced relented to java during solving the problems. And Also Visit Python  To learn More about Python

Leave a Comment

%d bloggers like this: