Object-Oriented Programming · Lesson 46 of 150
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.
01What 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.
02Why 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.
03Real-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.
04Syntax
javaClassName objectName = new ClassName();
05Example Program
javaclass 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