C++ OOPS
Object-Oriented Programming (OOP) is a way to structure programs using
objects — just like things in real life (like a car, dog, or student).
1. What is a Class?
A class is like a blueprint or template for creating things (objects).
It defines what properties (variables) and what actions (functions)
an object will have.
Think of it like a design or plan.
Real-Life Example:
Class: Car
Properties: color, brand, speed
Functions: start(), stop(), drive()
But this class doesn't represent any actual car — just the idea of a car.
2. What is an Object?
An object is a real item created using a class.
It has actual values inside it.
You can create many objects from one class.
Each object has its own data and can use the class functions.
Real-Life Example:
From class Car, you can create:
Car c1 = BMW, red
Car c2 = Audi, black
Each car (object) is based on the same class (design) but is a real, usable
thing.
#CODE:-
#include <iostream>
using namespace std;
// Creating a class
class Student {
public:
string name;
int age;
void introduce() {
cout << "Hello, my name is " << name << " and I am " << age
<< " years old." << endl;
}
};
int main() {
// Creating objects of the class Student
Student s1; // object 1
s1.name = "Pawan";
s1.age = 15;
s1.introduce(); // call function
Student s2; // object 2
s2.name = "Ravi";
s2.age = 14;
s2.introduce();
return 0;
}
// summary
Term Definition Example
Blueprint/template for
Class Car, Student, Animal
objects
Objec Real-world entity from a A red BMW, Pawan
t class (student)
Four Pillars of OOPs
1. Encapsulation
2.Abstraction
3. Abstraction 4. polymorphism