OOPs using C++ Notes
Subject Overview
OOPs using C++ moves students from procedural C into object-oriented C++ — classes and class declaration, constructors/
Subject at a glance
4
Units
29
Topics
5
Credits
4
Infographics
Unit-wise Syllabus
4 units — open any unit for detailed topic-wise notes, diagrams and important exam questions
- Object-oriented programming approach
- characteristics of OOP languages
- bridging C and C++
- structures and unions in C++
- class declaration — data members
- member functions
- private/public members
- data hiding and encapsulation
Encapsulation
Data and functions bundled in a class
Abstraction
Show what, hide how
Inheritance
Reuse a base class
Polymorphism
One interface, many forms
Study guide
This unit introduces the OOP approach: its characteristics, bridging from C to C++, structures and unions in C++, class declaration with data members and member functions, private and public members and data hiding and encapsulation. Model a real object such as a bank account as a class.
- Member function definitions inside/outside the class
- friend functions
- inline functions
- static members and functions
- scope resolution operator
- creating and accessing objects
- arrays of objects
- pass by value/reference
- default/parameterized/copy constructors
- destructors
Default
Creates an object with no arguments
Student s;
Parameterised
Initialises with given values
Student s(1, "Ana");
Copy
Creates a copy of another object
Student t(s);
Destructor
Cleans up when the object is destroyed
~Student()
Study guide
You study member functions inside and outside the class, friend, inline and static functions, the scope resolution operator, creating and accessing objects, arrays of objects, passing objects by value and reference, default, parameterised and copy constructors and destructors. Trace the order of constructor and destructor calls.
- Base and derived classes
- visibility modes (private/public/protected)
- single and multilevel inheritance
- protected member inheritance
- nesting of classes
- function and operator overloading (unary and binary)
public inheritance
public
protected
protected inheritance
protected
protected
private inheritance
private
private
Study guide
You study base and derived classes, visibility modes, single and multilevel inheritance, protected members, nested classes and function and operator overloading. Draw an inheritance diagram for each program you write.
- Early and late binding
- virtual functions and pure virtual functions
- streams/buffers/iostreams
- header files
- file input and output
Decided at
Compile time
Run time
Achieved by
Function and operator overloading
Virtual functions
Speed
Faster
Slightly slower
Flexibility
Less
More
Study guide
You study early and late binding, virtual and pure virtual functions, streams, buffers and iostreams and file input and output. Understand how a virtual function enables runtime polymorphism.
Why OOPs using C++ Matters
Object-oriented design is how most modern software is structured, and C++ OOP carries over to Java, Python and C#. OOP questions are a staple of technical interviews.
How to Prepare for OOPs using C++
- Code every concept: constructors, inheritance, overloading and virtual functions.
- Know the difference between overloading and overriding.
- Practise explaining OOP with real-life examples.
OOPs using C++: Frequently Asked Questions
What is encapsulation?
Encapsulation bundles data and the functions that operate on it into a single class and restricts direct access to the data.
What is a virtual function?
A virtual function is a member function that can be overridden in a derived class and is resolved at run time based on the actual object type.
