1.

Which among the following is correct for multiple inheritance?(a) class student{public:int marks;}s;class stream{int total;}; class topper:public student, public stream{};(b) class student{int marks;}; class stream{ }; class topper: public student{ };(c) class student{int marks;}; class stream:public student{ };(d) class student{ }; class stream{ }; class topper{ };The question was asked in final exam.My question is taken from Inheritance topic in chapter Inheritance & its Types of Object Oriented Programming

Answer»

The correct option is (a) CLASS student{public:int marks;}s;class stream{int total;}; class topper:public student, public stream{};

The best explanation: Class topper is getting DERIVED from 2 other CLASSES and hence it is multiple INHERITANCE. Topper inherits class stream and class student PUBLICLY and hence can use its features. If only few classes are defined, there we are not even using inheritance (as in option class student{ }; class stream{ }; class topper{ };).



Discussion

No Comment Found

Related InterviewSolutions