Skip to content
C

Object

An object is a real, usable instance created from a class. While a class is just a design, an object is the actual "thing" built using that design, with its own actual values stored in memory.


1. What is an Object?

An object is a real, usable instance created from a class. While a class is just a design, an object is the actual "thing" built using that design, with its own actual values stored in memory.

2. Why is it used?

Objects let a program actually work with real data based on a class's structure — like creating an actual Student object with a real name and roll number, rather than just describing what a Student should look like.

3. Real-Life Example

If a class is a blueprint for a house, an object is an actual house built from that blueprint, standing on real land, with a real address, and people actually living in it.

4. Syntax

java
ClassName objectName = new ClassName();

5. Example Program

java
class Car { String model; } public class ObjectDemo { public static void main(String[] args) { Car car1 = new Car(); car1.model = "Sedan"; System.out.println("Car model: " + car1.model); } }

Output:

Car model: Sedan

6. Key Points to Remember

  • The new keyword is used to create an object in Java.
  • Multiple objects can be created from the same class, each holding its own separate data.
  • Objects are stored in a memory area called the Heap.