OOP C++ Notes
OOP C++ Notes
Introduction to OOP
data and methods to manipulate that data. OOP contrasts with Procedure-Oriented Programming
1. **Abstraction**: Hiding the complex reality while exposing only the necessary parts.
2. **Encapsulation**: Bundling the data and methods that operate on the data within one unit, or
class.
3. **Inheritance**: Mechanism by which one class can inherit the properties and methods of another.
4. **Polymorphism**: Ability to present the same interface for different underlying forms (data types).
A class is a blueprint for creating objects. Objects are instances of classes that encapsulate both
data and methods that operate on that data. In C++, classes are defined using the 'class' keyword.
A constructor is a special member function that initializes objects of a class. It has the same name
as the class and is invoked when an object is created. A destructor is also a special member
function that is called when an object goes out of scope and is used to free resources.
Access Specifiers
Page 1
Detailed Notes on Object Oriented Programming using C++
1. **Public**: Members declared as public are accessible from outside the class.
2. **Private**: Members declared as private are accessible only within the class.
3. **Protected**: Members declared as protected are accessible in the class and in derived classes.
Inheritance
Inheritance allows a class to use properties and methods of another class. It helps in reusability of
code. Types of inheritance include single inheritance, multiple inheritance, and multilevel
inheritance.
Polymorphism
Polymorphism allows methods to do different things based on the object it is acting upon. It can be
achieved through function overloading (compile-time polymorphism) and function overriding (runtime
polymorphism).
Conclusion
OOP enhances the clarity and maintainability of code. By encapsulating data and functions together,
Page 2