Close
Close

OOP (Object Oriented Programming) in C++


Welcome to the new part of programming : Object Oriented Programming (OOP). To understand this, think of a book having a serial number and a number of pages. Now, your science book is a book as is your computer book. Suppose the serial number of Science book is SC12 and that of computer book is CS34 and the number of pages are 200 and 250 respectively. It is like in the picture below:

object and class in C++

So, here, 'book' is a class having attributes 'Page' and 'Serial number' and 'Science' and 'Computer' are objects(instances) of it.

So, now you understand that class is something which acts like a base, having some definitions. And objects are instances of class following those definitions.

One more example of class and objects you can think of is bank account. Think of 'Account' as a class having attributes 'min_balance' and 'rate_of_interest' and 'Saving' and 'Current' are its objects.

object and class in C++

I hope you have got the feel of classes and objects. We will be dealing with programming parts in later sections.

Member Functions


You already know what functions are. Member functions are functions defined inside a class. For example, there can be a function named 'getStrength' inside 'Student' class to get a total number of students. Here, 'getStrength' is the member function of 'Student' class.

Inheritance


Many times, we make a subclass of a class itself. The class whose subclass has been made is called superclass.
For example, 'Student' class can have 'BTech', 'MTech' and 'Phd' as its subclasses. Here, all three subclasses will have the properties of the parent class as well as some of their new properties.
Another example can be of 'Book' as superclass and 'ScienceBook' and 'MathsBook' as its subclasses.

All the shown methods and attributes of superclass will be shown by its subclass also. And subclass may have some different attributes in addition to those as well. Other names of superclass and subclass are base class and derived class respectively.

In this section, you have been introduced to some concepts of programming. In the following sections, you will go through the programming parts.

To learn from simple videos, you can always look at our C++ video course on CodesDope Pro. It has over 750 practice questions and over 200 solved examples.
Ask Yours
Post Yours
Doubt? Ask question