HackerRank C++ Inheritance Introduction




One of the important topics of Object Oriented Programming is Inheritance. Inheritance allows us to define a class in terms of another class, which allows us in the reusability of the code.



  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7. class Triangle
  8. {
  9. public:
  10. void triangle()
  11. {
  12. cout<<"I am a triangle\n";
  13. }
  14. };
  15. class Isosceles : public Triangle
  16. {
  17. public:
  18. void isosceles()
  19. {
  20. cout<<"I am an isosceles triangle\n";
  21. }
  22. //Write your code here.
  23. void description()
  24. {
  25. cout<<"In an isosceles triangle two sides are equal\n";
  26. }
  27. };
  28. int main()
  29. {
  30. Isosceles isc;
  31. isc.isosceles();
  32. isc.description();
  33. isc.triangle();
  34. return 0;
  35. }




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube