DEV Community

Cover image for #3 Known is a drop ! Introduction to Class & Objects
Deepikandas
Deepikandas

Posted on

#3 Known is a drop ! Introduction to Class & Objects

23/Feb/2026

What is a Class?

  • A class is defined as a template or blueprint from which objects are created.

  • It is a logical entity, not a physical one, meaning no memory allocation occurs for a class itself during program execution.

  • Memory is allocated only when an object is instantiated from the class.

  • A class does not occupy memory on its own. Memory is allocated when an object is created.

  • From one class, you can create multiple objects.
    A class Can contain:

variables → store object data

Methods → define behavior

Constructors → initialize objects

Static members → shared across all objects

Inner/nested classes → classes inside a class

Class -Nomenclature

Must start with:
A letter (A–Z or a–z)Or $ or _

Cannot start with a number

Cannot use Java keywords (class, public, static, etc.)

Case-sensitive → Student and student are different

No spaces or special characters allowed
Use PascalCase / UpperCamelCase eg: BankAccount
Syntax:
[access_modifier] class ClassName {
// Fields (variables)
// Constructor(s)
// Methods
}
What is an Object?
An object is an entity with state and behavior.
While a class is a blueprint, an object is the actual thing created in memory.

1️⃣ Objects are created using the new keyword (mostly)
2️⃣ Each object gets its own copy of instance variables
3️⃣ Methods can be shared, but fields are object-specific
4️⃣** Memory for the object is allocated in the heap**

Syntax for object creation:
ClassName objectName = new ClassName();
Student s1 = new Student();

Class vs Objects

Fun Facts About Classes and Objects in Java
1️⃣ Classes Are Just Blueprints

A class itself does not occupy memory.

Only when you create an object does memory get allocated in the heap.

Think of it like: blueprint of a car vs. actual car 🚗

2️⃣ One Class, Many Objects

You can create multiple objects from the same class.

Each object has its own copy of instance variables.

Example: s1.name = "RK" and s2.name = "Aisha" — same class, different state!

3️⃣ References Are Like Nicknames

The variable pointing to an object is called a reference.

Multiple references can point to the same object, but there’s still one object in memory.

Example: Student s3 = s1; → s3 and s1 now point to the same object

4️⃣ Objects Live in Heap, References in Stack

Heap = stores objects

Stack = stores references and local variables

That’s why modifying an object through one reference affects all references pointing to it

Top comments (0)