Skip to content

Commit

Permalink
Merge pull request #44 from rpandox/feat/mult-levl-inheritance-q2
Browse files Browse the repository at this point in the history
feat: add question 2 to multilevel inheritance
  • Loading branch information
gaurovgiri authored Oct 22, 2024
2 parents 9e1dbef + 8aa94a7 commit 95d9700
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
46 changes: 46 additions & 0 deletions programs/Inheritance/Multilevel Inheritance/q2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <iostream>
using namespace std;

// Base class
class Base
{
public:
void displayBase()
{
cout << "This is the Base class." << endl;
}
};

// Intermediate class derived from Base
class Intermediate : public Base
{
public:
void displayIntermediate()
{
cout << "This is the Intermediate class." << endl;
}
};

// Derived class derived from Intermediate
class Derived : public Intermediate
{
public:
void displayDerived()
{
cout << "This is the Derived class." << endl;
}
};

// Main function
int main()
{
// Creating an object of the Derived class
Derived obj;

// Accessing methods from all levels of inheritance
obj.displayBase(); // Method from Base class
obj.displayIntermediate(); // Method from Intermediate class
obj.displayDerived(); // Method from Derived class

return 0;
}
4 changes: 2 additions & 2 deletions programs/Inheritance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
## Multilevel Inheritance

- [x] [q1](./Multilevel%20Inheritance/q1.cpp): WAP to show multi level inheritance.
- [ ] [q2](./Multilevel%20Inheritance/q2.cpp): WAP to show multilevel inheritance with base, intermediate, and derived class.
- [ ] [q3](./Multilevel%20Inheritance/q3.cpp): WAP to demonstrate multilevel inheritance where each class has its own method.
- [x] [q2](./Multilevel%20Inheritance/q2.cpp): WAP to show multilevel inheritance with base, intermediate, and derived class.
- [x] [q3](./Multilevel%20Inheritance/q3.cpp): WAP to demonstrate multilevel inheritance where each class has its own method.
- [ ] [q4](./Multilevel%20Inheritance/q4.cpp): WAP to show multilevel inheritance where each class contains its own constructor and destructor.
- [ ] [q5](./Multilevel%20Inheritance/q5.cpp): WAP to demonstrate multilevel inheritance with virtual functions.
- [ ] [q6](./Multilevel%20Inheritance/q6.cpp): WAP to show multilevel inheritance where the derived class overrides methods from both intermediate and base classes.
Expand Down

0 comments on commit 95d9700

Please sign in to comment.