What is the syntax of inheritance of class?
What does inheriatance allows you to do?
What is the output of this program?
1. #include2. using namespace std; 3. class BaseClass 4. { 5. public: 6. virtual void myFunction() 7. { 8. cout << "1"; 9. } 10. }; 11. class DerivedClass1 : public BaseClass 12. { 13. public: 14. void myFunction() 15. { 16. cout << "2"; 17. } 18. }; 19 class DerivedClass2 : public DerivedClass1 20. { 21. public: 22. void myFunction() 23. { 24. cout << "3"; 25. } 26. }; 27. int main() 28. { 29. BaseClass *p; 30. BaseClass ob; 31. DerivedClass1 derivedObject1; 32. DerivedClass2 derivedObject2; 33. p = &ob; 34. p -> myFunction(); 35. p = &derivedObject1; 36. p -> myFunction(); 37. p = &derivedObject2; 38. p -> myFunction(); 39. return 0; 40. }
What is the output of this program?
1. #include2. using namespace std; 3. class BaseClass 4. { 5. int x; 6. public: 7. void setx(int n) 8. { 9. x = n; 10. } 11. void showx() 12. { 13. cout << x ; 14. } 15. }; 16. class DerivedClass : private BaseClass 17. { 18. int y; 19. public: 20. void setxy(int n, int m) 21. { 22. setx(n); 23. y = m; 24. } 25. void showxy() 26. { 27. showx(); 28. cout << y << '\n'; 29. } 30. }; 31. int main() 32. { 33. DerivedClass ob; 34. ob.setxy(10, 20); 35. ob.showxy(); 36. return 0; 37. }
Pick out the correct statement about multiple inheritance.