Quiz on Inheritance in C++
In the world of object-oriented programming, inheritance is one of the major topics. Please give this topic your special attention since it is very important. Let’s begin the quiz on inheritance in C++ without wasting any more time. I wish you all the best!
0 of 15 Questions completed Questions: You have already completed the quiz before. Hence you can not start it again. Quiz is loading… You must sign in or sign up to start the quiz. You must first complete the following: 0 of 15 Questions answered correctly Your time: Time has elapsed You have reached 0 of 0 point(s), (0) Earned Point(s): 0 of 0, (0) #include<iostream> using namespace std; class Base { public: Base() { cout << “Base class constructor called” << endl; } }; class Derived: public Base { public: Derived() { cout << “Derived class constructor called” << endl; } }; int main() { Derived d; return 0; } #include<iostream> using namespace std; class Departments { public: Departments() { cout << “Department class constructor called” << endl; } ~Departments() { cout<<“Department class destructor called”<<endl; } }; class Colleges { public: Colleges() { cout<<“Colleges class constructor called”<<endl; } ~Colleges() { cout<<“Colleges class destructor called”<<endl; } }; class Students: public Departments,public Colleges { public: Students() { cout << “Students class constructor called” << endl; } ~Students() { cout<<“Students class destructor called”<<endl; } }; int main() { Students s; return 0; } #include<iostream> using namespace std; class Parent { public: Parent() { cout<<“Parent class”; } }; class Child: public Parent { public: Child() { cout<<“Child class”; } }; int main() { Parent *pa = new Child; Child *ch = new Parent; } Class Child:protected Parent #include <iostream> using namespace std; class Parent { public: int variable; }; class Child : public Parent { public: void show() { variable=10; cout << variable; } }; int main() { Child c; c.show(); return 0; } #include <iostream> #include <string> using namespace std; class Parent { private: float d; public: int a; void edit(int i){ a = i; } void get_val_a(){ cout<<a; } }; class Child: public Parent { int a = 25; public: void print(){ cout<<a; } }; int main() { Child c; c.edit(10); c.print(); c.get_val_a(); return 0; } #include <iostream> using namespace std; class University { public: University() { cout << “This is a University” << endl; } }; class Colleges { public: Colleges() { cout<<“Constructor of colleges\n”; } }; class Departments: public University { }; class Students: public University, public Colleges { public: Students() { cout<<“constructor of Students class is called”; } }; int main() { Students b1; return 0; } #include <iostream> using namespace std; class University { public: int u; }; class Departments : public University { public: int d; }; class Colleges : public University { public: int c; }; class Students : public Departments, public Colleges { public: int s; }; int main() { Students stu; stu.Departments::u = 10; stu.Colleges::u = 100; cout << stu.Departments::u; cout << stu.Colleges::u; return 0; } #include <iostream> using namespace std; class University { public: int u; }; class Departments : public University { public: int d; }; class Colleges : public University { public: int c; }; class Students : public Departments, public Colleges { public: int s; }; int main() { Students stu; stu.u = 10; stu.u = 100; cout<< stu.Departments::u; cout<< stu.Colleges::u; return 0; } Quiz Summary
Information
Results
Results
0 Essay(s) Pending (Possible Point(s): 0) Categories
1. Question
2. Question
3. Question
4. Question
5. Question
6. Question
7. Question
8. Question
9. Question
10. Question
11. Question
12. Question
13. Question
14. Question
15. Question
Summary
A big part of OOP is inheritance, which is one of the main concepts in any programming language. You may have learned more about inheritance with the quiz. We recommend moving forward only after you understand all the concepts used. In the meantime, have a good learning experience!
Thank you for opportunities ☺️