Single inheritance in C++ with Syntax and Examples

Single inheritance in C++ OOP, Syntax of single inheritance, Example of single inheritance 

What is single inheritance?

In single inheritance child class is derived from only and only one parent class.

Syntax to inherit the class from the parent class in single inheritance?

Serial#Code
1class child_class_name : Access_specifier Parent_class_name
2{
3Body of the class;
4};

Example of single inheritance

single inheritance of classes

Output

enter n1?

3

enter n1?

2

sum=5

Difference between Single and multiple Inheritance in C++

Here, i am showing you a comparison of Single and multiple Inheritance in C++.

SINGLE INHERITANCEMULTIPLE INHERITANCE
In Single inheritance derived class have only single base class.In Multiple inheritance derived class have more than one base class.
Less overhead in single inheritance and  requires small run time as compared to multiple inheritance.More overhead in Multiple inheritance and  requires more run time as compared to single inheritance.
Single inheritance is a lot of close to specialization.Multiple inheritance is a lot of close to generalization.
Syntax of single inheritance is

Class DerivedClass_name : access_specifier Base_Class{};.

Syntax of multiple inheritance is

Class DerivedClass_name : access_specifier Base_Class1, access_specifier Base_Class2, ….{}; .

Single inheritance is simple as compared to the multiple inheritance.Multiple inheritance is more complex as compared to the single inheritance.
Mostly all of the programming languages supports Single inheritance.Multiple inheritance is supported by C++ but Multiple inheritance can’t be implemented in most of other programming languages e.g, C# and Java doesn’t support multiple inheritance through classes.

Exercise and Solution Single inheritance

  1. WAP in C++ to display such a pattern for n number of rows using a number which will start with the number 1 and the first and the last number of each row will be 1 with the help of multiple inheritances.
  2. C++ program to print a hollow square or rectangle star pattern with the support of single inheritance..
  3. Single inheritance C++ to display the n terms of odd natural number and their sum.
  4. Single inheritance C++ program to convert a decimal number into binary.
  5. Single inheritance C++ program to display the pattern like a pyramid using the alphabet using single inheritance.
  6. Single inheritance C++ program to find the perfect numbers within a given range.
  7. Single inheritance C++ program to show the sum of an A.P. series.
  8. Single inheritance C++ program to print the string in reverse order.
  9. Single inheritance C+ Program Armstrong number of n digits.
  10. single inheritance C++ program to display patterns like the right angle.
  11. Single inheritance C++ program pattern like a pyramid repeat.
  12. Single inheritance C++ program to display the cube of the number up to a given integer.
  13. Single inheritance C++ Program to convert a decimal number into binary.
  14. Single Inheritance C++ program to find Strong Numbers within a range of numbers.
  15. C++ program to find HCF using single inheritance.
  16. Write a C++ program to print the rhombus star pattern of N rows using Single Inheritance.
  17. Write a program in C++ to convert a decimal number to hexadecimal using the single inheritance in object-oriented programming (OOP).
  18. Write a program in C++ to convert a decimal number into an octal without using an array using Single inheritance in object-oriented programming(OOP).
  19. C++ program to display Pascal’s triangle using the single inheritance.
  20. Single inheritance C++ program to print hollow rhombus, parallelogram star pattern.
  21. Single Inheritance C++ program to print mirrored right triangle star pattern.
  22. Single inheritance C++ Program to convert an octal number into binary.
  23. Single inheritance Floyd Triangle C++.
Test Your Understandings

1.In single inheritance multiple child can have multiple parent classes? YES / NO

Answer - Click Here:
NO

2.class child_class_name : Access_specifier parent_class_name is the correct syntax for creating child class? YES / NO

Answer - Click Here:
Yes

Topic Covered

Single inheritance in C++ OOP, Syntax of single inheritance, Example of singe inheritance .

Subscribe for Friendship

Latest posts by Prof. Fazal Rehman Shamil (see all)

Buy advertisement space on T4Tutorials

For more details email [email protected]