These are the three fundamental components you commonly define inside a Java class:


1. Fields

A field is a variable declared inside a class that represents the state/data of an object.

class Student {
    String name;
    int age;
}

Here:

name → Field
age  → Field

Each object gets its own copy of instance fields.

Student s1 = new Student();
Student s2 = new Student();

s1.name = "Rahul";
s2.name = "Aman";

Conceptually:

s1
├── name = "Rahul"
└── age  = 0

s2
├── name = "Aman"
└── age  = 0

What happens under the hood?

When you create:

Student s1 = new Student();

Java creates an object in heap memory.

The object's instance fields are stored as part of that object.

Stack                         Heap

s1 ───────────────────────→  Student Object
                              ├── name
                              └── age