Home | | Object Oriented Programming and Data Structures | Important Short Questions and Answers: Inheritance and Polymorphism

Chapter: Object Oriented Programming and Data Structure : Inheritance and Polymorphism

Important Short Questions and Answers: Inheritance and Polymorphism

Object Oriented Programming and Data Structure - Inheritance and Polymorphism - Important Questions and Answers: Inheritance and Polymorphism

 

1. What are templates?

 

·        Template is one of the features added to C++.

 

·        It is new concepts which enable us to define generic classes and functions and thus provides support for generic programming.

 

·        A template can be used to create a family of classes or functions.

 

2. Illustrate the exception handling mechanism.

 

C++ exception handling mechanism is basically upon three keywords, namely,

try, throw, and catch.

 

try is used to preface a block of statements which may generate exceptions.

throw - When an exception is detected, it is thrown using a throw statement in the try block.

Catch- A catch block defined by the keyword catch ‘catches’ the exception ‘thrown’ by the

 

thrown statement in the try block and handles its appropriately.

 

3. What happens when a raised exception is not caught by catch block?

 

·        If the type of object thrown matches the arg type in the catch statement, then catch block is executed for handling the exception.

 

·        If they do not match the program is aborted with the help of abort() function which is invoked by default.

 

·        When no exception is detected and thrown, the control goes to the statement immediately after the catch block. That is the catch block is skipped.

 

4. Give the syntax of a pointer to a function which returns an integer and takes arguments one of integer type and 2 of float type. What is the difference between a class and a structure?

 

int (X_fun) (int, float);

 

5. What is a template? What are their advantages

 

·        A template can be used to create a family of classes or functions.

 

·        A template is defined with a parameter that would be replaced by a specified data type at the time of actual use of the class or functions. Supporting different data types in a single framework.

 

·        The template are sometimes called parameterized classes or functions.

 

6. How is an exception handled in C++?

Exceptions are run time anomalies or unusual conditions that a program may encounter while executing.

1. Find the problem (Hit the exception)

2. Inform that an error has occurred.( Throw the exception)

3. Receive the error information. ( Catch the exception)

4. Take corrective actions.( Handle the exception)

 

7. What is function template? Explain.

 

·        Like class template, we can also define function templates that could be used to create a family of functions with different argument types.

 

·        The general format of a function template is: template<class T>

 

returntypefunctionname ( arguments of type T)

{

// ………

 

//……….Body of function with type T wherever appropriate //………..

}

 

8. List five common examples of exceptions.

 

·        Division by zero

·        Access to an array outside of its bounds

·        Running out of memory or disk space.

 

9. What is class template?

 

·        Templates allows to define generic classes. It is a simple process to create a generic class using a template with an anonymous type.

 

·        The general format of class template is:

 

template<class T> classclassname

{

// ………class member specification.

 

//………. with anonymous type T wherever appropriate //……,…..

}

 

 

10. What are 3 basic keywords of exception handling mechanism?

 

C++ exception handling mechanism is basically built upon three keywords

 

·        try

·        throw

·        catch

11. What are the c++ operators that cannot be overloaded?

 

Size operator (sizeof)

 

Scope resolution operator (::) member access operators(. , .*) Conditional operator (?:)

 

12. What is a virtual base class?

 

When a class is declared as virtual c++ takes care to see that only copy of that class is inherited, regardless of how many inheritance paths exist between the virtual base class and a derived class.

 

13. What is the difference between base class and derived class?

 

The biggest difference between the base class and the derived class is that the derived class contains the data members of both the base and its own data members. The other difference is based on the visibility modes of the data members.

 

14. What are the rules governing the declaration of a class of multiple inheritance?

 

More than one class name should be specified after the : symbol.

Visibility modes must be taken care of.

 

If several inheritance paths are employed for a single derived class the base class must be appropriately declared

 

15. Mention the types of inheritance.

 

1.Single inheritance.

2. Multiple inheritance.

3. Hierarchical inheritance.

4. Multilevel inheritance.

5. Hybrid inheritance.

 

6. Define dynamic binding.

 

Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run-time.

 

17. What do u mean by pure virtual functions?

 

A pure virtual function is a function declared in a base class that has no definition relative to the base class. In such cases, the compiler requires each derived class to either define the function or redeclare it as a pure virtual function. A class containing pure virtual functions cannot be used to declare any objects of its own.

 

18. Mention the key words used in exception handling.

The keywords used in exception handling are

throw

try

catch

 

19. List the ios format function.

 

The ios format functions are as follows:

width()

precision()

fill()

setf()

unsetf()

 

20. List the manipulators.

 

The manipulators are:

setw()

setprecision()

setfill()

setiosflags()

resetiosflags()

 

21.            Mention the equicalent ios function for manipulators.

 

Manipulator Equivalent ios function setw(int w) width()

 

setprecision(int d) precision() setfill(int c) fill() setiosflags(long f) setf() resetiosflags(long f) unsetf() endl “\n”

 

22.            Define fill functions.

 

The fill( ) function can be used to fill the unused positions of the field by any desired character rather than by white spaces (by default). It is used in the following form: cout.fill(ch);

 

where ch represents the character which is used for filling the unused positions. For example,

 

the statements cout.fill(‘*’);

 

cout.width(10); cout<<5250<<”\n”;

 

23 .Give the syntax of exception handling mechanism.

 

The syntax of exception handling mechanism is as follows:

try

{

---------------------

throw exception

---------------------

}

catch(type arguments)

{

---------------------

---------------------

}

----------------------

----------------------

 

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Object Oriented Programming and Data Structure : Inheritance and Polymorphism : Important Short Questions and Answers: Inheritance and Polymorphism |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.