Category Archives: Library

45. Single inheritance

Single inheritance is defined as the inheritance in which a derived class is inherited from the only one base class. Where ‘A’ is the base class, and ‘B’ is the derived class. Single Level Inheritance Example: Inheriting Fields When one class inherits another class, it is known as single level inheritance. Let’s see the example of… Read More »

44. Inheritance

One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time. When creating a class, instead of… Read More »

43. Virtual Base Class

Virtual base classes are used in virtual inheritance in a way of preventing multiple “instances” of a given class appearing in an inheritance hierarchy when using multiple inheritances. Need for Virtual Base Classes:Consider the situation where we have one class A . This class is A is inherited by two other classes B and C. Both these classes are inherited into another… Read More »

42. Virtual Function

A C++ virtual function is a member function in the base class that you redefine in a derived class. It is declared using the virtual keyword. It is used to tell the compiler to perform dynamic linkage or late binding on the function. There is a necessity to use the single pointer to refer to… Read More »

41. Pure virtual functions

A pure virtual function is a virtual function that has no definition within the class. Let’s understand the concept of pure virtual function through an example. In the above pictorial representation, shape is the base class while rectangle, square and circle are the derived class. Since we are not providing any definition to the virtual… Read More »

40. Function Overriding

If derived class defines same function as defined in its base class, it is known as function overriding in C++. It is used to achieve runtime polymorphism. It enables you to provide specific implementation of the function which is already provided by its base class. Let’s see a simple example of Function overriding in C++.… Read More »

39. Operator Overloading

Operator overloading is a compile-time polymorphism in which the operator is overloaded to provide the special meaning to the user-defined data type. Operator overloading is used to overload or redefines most of the operators available in C++. It is used to perform the operation on the user-defined data type. For example, C++ provides the ability… Read More »

38. Function Overloading

Function Overloading is defined as the process of having two or more function with the same name, but different in parameters is known as function overloading in C++. In function overloading, the function is redefined by using either different types of arguments or a different number of arguments. It is only through these differences compiler… Read More »

36. Overloading

If we create two or more members having the same name but different in number or type of parameter, it is known as C++ overloading.  In C++, we can overload: methods, constructors, and indexed properties It is because these members have parameters only. Types of overloading in C++ are: Function overloading Operator overloading C++ allows… Read More »

36. Encapsulation

All C++ programs are composed of the following two fundamental elements − Program statements (code) − This is the part of a program that performs actions and they are called functions. Program data − The data is the information of the program which gets affected by the program functions. Encapsulation is an Object Oriented Programming concept that… Read More »