This challenge is an extension of a previous challenge named Inheritance-Introduction. We highly recommend solving Inheritance-Introduction before solving this problem.<\/em><\/p>\n\n\n\nIn the previous problem, we learned about inheritance and how can a derived class object use the member functions of the base class.<\/p>\n\n\n\n
In this challenge, we explore multi-level inheritance. Suppose, we have a class A which is the base class and we have a class B which is derived from class A and we have a class C which is derived from class B, we can access the functions of both class A and class B by creating an object for class C. Hence, this mechanism is called multi-level inheritance<\/em>. (B inherits A and C inherits B.)<\/p>\n\n\n\nCreate a class called Equilateral<\/em> which inherits from Isosceles<\/em> and should have a function such that the output is as given below.<\/p>\n\n\n\nI am an equilateral triangle\nI am an isosceles triangle\nI am a triangle<\/code><\/pre>\n\n\n\n<\/span>Solution – Multi Level Inheritance in C++<\/strong><\/span><\/h2>\n\n\n\n<\/span>C++<\/strong><\/span><\/h3>\n\n\n\n#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nclass Triangle{\n\tpublic:\n\t\tvoid triangle(){\n\t\t\tcout<<\"I am a triangle\\n\";\n\t\t}\n};\n\nclass Isosceles : public Triangle{\n \tpublic:\n \t\tvoid isosceles(){\n \t\tcout<<\"I am an isosceles triangle\\n\";\n \t\t}\n};\n\n\/\/Write your code here.\nclass Equilateral:public Isosceles\n{\npublic:\nvoid equilateral()\n{\ncout<<\"I am an equilateral triangle\\n\";\n}\n};\n\nint main(){\n \n Equilateral eqr;\n eqr.equilateral();\n eqr.isosceles();\n eqr.triangle();\n return 0;\n}\n<\/pre>\n\n\n\n