OOPS Extended Notes
OOPS Extended Notes
### Definition:
Variables are named storage locations in memory. Data types define what type of data a variable can hold.
Constants have fixed values that do not change. Operators perform operations on variables.
### Explanation:
1. 'int a' declares an integer variable.
2. 'const float pi' creates a constant floating-point variable.
3. 'sum = a + 5' performs an addition.
4. 'cout' displays the result.
### Definition:
Control structures manage the flow of execution (if-else, loops). Functions modularize code for reuse.
### Explanation:
1. 'void greet()' defines a function.
2. 'cout' prints text.
3. 'greet()' is called inside main().
### Definition:
Arrays store multiple values of the same type. Pointers store memory addresses.
Object-Oriented Programming (OOPS) - Handwritten Notes
### Explanation:
1. 'arr[3]' creates an array.
2. 'ptr = arr' assigns array address to pointer.
3. '*ptr' accesses first element.
### Definition:
A class is a blueprint for objects. An object is an instance of a class.
### Explanation:
1. 'class Car' defines a class.
2. 'string brand' is a data member.
3. 'show()' is a method.
4. 'Car myCar' creates an object.
5. 'myCar.brand = "Toyota"' assigns value.
6. 'myCar.show()' calls method.
5. Inheritance
### Definition:
Inheritance allows a class to derive properties from another class.
#include <iostream>
using namespace std;
class Vehicle {
public:
int wheels;
};
class Car : public Vehicle {
public:
string brand;
};
int main() {
Car myCar;
myCar.wheels = 4;
myCar.brand = "BMW";
cout << "Car brand: " << myCar.brand << ", Wheels: " << myCar.wheels;
return 0;
}
### Explanation:
1. 'class Vehicle' is a base class.
2. 'class Car : public Vehicle' derives from Vehicle.
3. 'myCar.wheels' accesses inherited property.
6. Polymorphism
### Definition:
Polymorphism allows methods to have different implementations.
### Explanation:
1. 'virtual void sound()' enables polymorphism.
2. 'Dog::sound()' overrides base class function.
3. 'a->sound()' calls derived class method dynamically.
Object-Oriented Programming (OOPS) - Handwritten Notes
### Definition:
A constructor initializes objects. A destructor releases memory.
### Explanation:
1. 'Car()' is a constructor that runs automatically.
2. '~Car()' is a destructor that runs when object is destroyed.
8. Operator Overloading
### Definition:
Allows redefining the behavior of operators for objects.
### Explanation:
1. 'operator+' overloads '+'.
Object-Oriented Programming (OOPS) - Handwritten Notes