OOP is a way to write programs by using objects, like things in real life.
Object = Data + Actions
It makes programs easy to understand and reuse.
Four important Ideas:
Encapsulation – Keep data and actions together.
Abstraction – Show only important things, hide the rest.
Inheritance – New objects can use old object’s stuff.
Polymorphism– Objects can do the same action in different ways.
Example: Car
Data: color, speed
Actions: start(), stop(), accelerate()
Class and Object
A class is like a blueprint or template for making objects.
It tells what data the object will have and what actions/functions it can do.
But by itself, a class is not a real object—it’s just the plan.
Example:
Class = Car (the blueprint)
Object = myCar (a real car made from the blueprint)
In short:
Class = Plan
Object = Thing made from that plan
class Classname{
access specifier:
data member;
member function(){};
};
Top comments (0)