Class Inheritance, Member Access and Constructor – CSKC
Sign In

Search





Q&A #5267 siteicon  

Question:

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?

 

Answer:

(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

C. Sir| Created: 4-Dec-2018 | Updated: 22-Mar-2026|CBSE12A-2018









×
ssignment 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 Display Using IO Manipulation User Defined Data Types Enumerated Types Preprocessor Directives And Macros Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constructor Concepts Default Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Mult-Level Inheritance Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Stacks Queues Introductory Sessions Beginning to Program Tokens Keywords Identifiers Literals Data Types Variables and Constants Operators (Arithmetic-Assignment-Unary-Relational-Logical) Expressions Statements and Formula Based Calculations Class Object Creation and Access Wrapper Classes Constructor Basics Conversion and Checking Functions Math Functions Function building and calling Simple If and If-Else Selection Switch Based Selections Basic Loop Types Array Basics Array Search Array Sorting Character Handling String Basics String Class Functions Types of Errors Try Catch Introductory Sessions Beginning to Program Introductory Sessions Beginning to Program Introductory Sessions Beginning to Program Data Types Variables and Constants Introductory Sessions Beginning to Program Date and Time Handling Regular Expressions Command Line Arguments Concurrent Execution Making Executable File Python Introduction (Features Python Introduction (Features, Installation, Modes) Handling Unicode Internet Interactions Imaging and Compression Special Data File Handling Python Basics Cryptography Blockchain and Cryptocurrency Generative AI keywords, identifiers, variables Beginning To Program Tokens, Keywords, Identifiers Variables and Expressions Data Types Operators Concept Learning Examples Operators Solved Practical Examples elational nary)