






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







2. Object
Employee emp("Geek", 10000.0f); emp.displayDetails(); return 0 ; }
Employee: Geek Salary: 10000
3. Abstraction
#include
void brake() override { cout << "Car: Applying brakes..." << endl; } }; int main() { // Create object using pointer to abstract class Vehicle* myCar = new Car(); myCar->startEngine(); myCar->accelerate(); myCar->brake(); delete myCar; return 0 ; }
Engine started! Car: Pressing gas pedal... Car: Applying brakes...
4. Encapsulation
// Getter methods int getId() { return id; } string getName() { return name; } }; int main() { Employee emp; // Using setters emp.setId( 101 ); emp.setName("Geek"); // Using getters cout << "Employee ID: " << emp.getId() << endl; cout << "Employee Name: " << emp.getName() << endl; return 0 ; }
Employee ID: 101 Employee Name: Geek
5. Inheritance
Inheritance
#include
Types of Polymorphism
Function Overloading and Function Overriding
#include
// Parent Class class Parent { public: // Overloaded method void func() { cout << "Parent.func()" << endl; } // Overloaded method virtual void func(int a) { cout << "Parent.func(int): " << a << endl; } }; // Child Class class Child : public Parent { public: // Overrides Parent.func(int) void func(int a) override { cout << "Child.func(int): " << a << endl; } }; int main() { Parent parent; Child child; Parent* polymorphicObj = new Child(); // Method Overloading (compile-time) parent.func(); parent.func( 10 ); // Method Overriding (runtime) child.func( 20 ); // Polymorphism in action polymorphicObj->func( 30 ); delete polymorphicObj; return 0 ; }