Class Inheritance, Member Access and Constructor – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-CBSE12A-2018-02D #CPP#5267    siteicon   siteicon  

Problem Statement - Class Inheritance, Member Access and Constructor

Answer the questions (i) to (iv) based on the following:

class Teacher
{
  int TCode;
  protected:
  char Name[20];
  public:
  Teacher();
  void Enter(); void Show();
};
class Course
{
  int ID;
  protected:
  Char Title[30];
  public:
  Course();
  void Initiate();
  void Display();
};
class Schedule: public Course, private Teacher
{
  int DD,MM,YYYY;
  public:
  Schedule();
  void Start();
  void View();
};
void main()
{
  Schedule S;
}

(i) Which type of Inheritance out of the following is illustrated in the above example?
Single Level Inheritance, Multilevel Inheritance, Multiple Inheritance
(ii) Write the names of all the members, which are directly accessible by the member
function View() of class Schedule.
(iii) Write the names of all the members, which are directly accessible by the object S
of class Schedule declared in the main() function.
(iv) What will be the order of execution of the constructors, when the object S of class
Schedule is declared inside main() function?

 

Solution

TC++ #5267

(i) Multiple Inheritance
(ii) Members accessible by function View() of class Schedule
Start(), DD, MM, YYYY, Display(), Initiate(), Title, Enter(), Show(), Name, View()
(iii) Members accessible by object S of class Schedule:
View(),Start(),Display(), Initiate()
(iv) Order of execution of constructors for object S.
Course(), Teacher(), Schedule()

Notes

(i) Multiple Inheritance
It is multiple inheritance because class Schedule is Inherited from more than 1 parent class which is Course and Teacher

(ii) Members accessible by function View() of class Schedule
Start(), DD, MM, YYYY, Display(), Initiate(), Title, Enter(), Show(), Name, View()

The function View is within the class so all the public and protected members of Parent classes will be accessible (whether inherited publicly or privately) and all the members of the same class will be accessible.

(iii) Members accessible by object S of class Schedule:
View(),Start(),Display(), Initiate()

The object S is outside the class, so only public members of same class and public members of parent class would be accessible.

(iv) Order of execution of constructors for object S.
Course(), Teacher(), Schedule()

Constructors of parent classes will execute first with the order in which they are inherited and then the constructor of class itself will execute.

 


Share

CSKC| Created: 4-Dec-2018 | Updated: 13-Dec-2018|CBSE12A-2018






×
Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning 2D Array Memory Addressing Display Using IO Manipulation Display Using C Formatting Tricks User Defined Data Types Enumerated Types Preprocessor Directives And Macros Exception Handling Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Function Overloading Special Cases Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constant Functions Nesting of Functions Class Members Scope Resolution Static Members in a Class Array of Objects Constructor Concepts Default Constructor Parameterized Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Multi-Level Inheritance Class Nesting Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Pointers and Functions Object Pointers This Pointer Linked Lists Stacks Queues


Back