Home | | Object Oriented Programming | Important Short Questions and Answers: OOP - Advanced Programming

Chapter: Object Oriented Programming(OOP) : Advanced Programming

Important Short Questions and Answers: OOP - Advanced Programming

Object Oriented Programming(OOP) - Advanced Programming -

 

1.       Define Template. 

          A  template  in  C++  allows  the  construction  of  a  family  of  template

          functions and classes to perform the same operation on different data types. The template

          type arguments are called “generic data types”.

2.       Define function template.

          The templates declared for functions are called function templates. A function

          template is prefixed with a keyword template and list of template type arguments.

3.       What is the syntax used for writing function template?

          template      <class T>,……….>

          class name function name(arguments)

          {       

          Body of template function

          }       

4.       Define class template.

          The templates declared for classes are called class templates. Classes can also be

          declared to operate on different data types. A class template specifies how individual

          classes can be constructed similar to normal class specification.

5.       What is the syntax used for writing class template?

          template      < class T1, class T2, ……. >

          class class name

          {       

          // data items of template type T1, T2……..

          // functions of template arguments T1, T2 …

          };      

6.       Define exception handling process.

          The error handling mechanism of C++ is generally referred to as an exception

          handling. It provides a mechanism for adding error handling mechanism in a program.

7.       What are the two types of an exception?

          There are two types of an exception.

* Synchronous exception.

*        Asynchronous exception.

8.       How many blocks contained in an exception handling model?

Totally three blocks contained in an exception handling process.

1. Try block

2.Throw block

3.Catch block

 

 

9.  Define throw construct.

 

The keyword throw is used to raise an exception when an error is generated in the computation. The throw expression initializes a temporary object of the type T used in throw.

 

Syntax:            throw T // named object, nameless object or by default nothing.

 

10. Define catch construct.

 

The exception handler is indicated by the keyword catch. It must be used immediately after the statements marked by the keyword try. Each catch handler will evaluate an exception that matches to the specified type in the argument list.

 

Syntax:

Catch (T) // named object or nameless object

 

{

Actions for handling an exception

}

11. Define try construct.

 

Try keyword defines a boundary within which an exception can occur. The try keyword is a block of code enclosed by braces. This indicates that the program is prepared to test for the exceptions. If an exception occurs, the program flow is interrupted.

 

Syntax:

try

{

Code raising an exception

}

catch (type_id1)

{

Actions for handling an exception

}

…………….

…………….

catch (type_idn)

{

 

Actions for handling an exception

}

 

12.                        What are the tasks performed by an error handling mechanism?

*  Detect the problem causing an exception(hit the exception)

*  inform that an error has occurred(throw the exception)

*  receive the error information(catch the exception)

*  Take correct actions(handle the exception)

 

13.                        Define exception specification.

 

It is possible to specify what kind of exception can be thrown by functions, using a specific syntax. We can append the function definition header with throw keyword and

 

 

possible type of expressions to be thrown in the parenthesis. It is known as exception specification.

 

14.                        What are the two types of an exception specification?

1.     Terminate () function.Unexpected () function.

15.                        Define terminate () function.

 

Terminate () is the function which calls abort () function to exit the program in the event of runtime error related to the exception.

 

16. Define unexpected () function.

 

If a function throws an exception which is not allowed, then a function unexpected () is called which is used to call abort () function to exit the program from its control. It is similar to Terminate () function.

 

17. Define multiple catch.

 

Using more than one catch sections for a single try block. At first matching, catch block will get executed when an expression is thrown. If no matching catch block is found, the exception is passed on one layer up in the block hierarchy.

 

18. Define catch all exception.

 

It is possible for us to catch all types of exceptions in a single catch section. We can use catch (…) (three dots as an argument) for representing catch all exception.

 

19. Define An Exception.

 

Exceptions refer to unusual conditions or errors occurred in a program. 20. Define synchronous exception.

 

This type of an exception occurs during the program execution due to some fault in the input data or technique is known as synchronous exception.

 

Examples are errors such as out-of-range, overflow, and underflow. 21. Define asynchronous exception.

 

The exceptions caused by events or faults that are unrelated to the program. Examples are errors such as keyboard interrupts, hardware malfunctions and disk failures.

 

22. Define inheritance.

 

Inheritance is the most important property of object oriented programming. It is a mechanism of creating a new class from an already defined class. The old class is referred to as base class. And the new one is called derived class.

 

23.  What are the advantages of an inheritance?

*  Inheritance is used for extending the functionality of an existing class.

 

*  By using this, we have multiple classes with some attributes common to them.

 

*  We HAVE to avoid problems between the common attributes.

*  It is used to model a real-world hierarchy in our program.

 

24.                        How to derive a derived class from the base class?

 

A Derived class is defined by specifying its relationship with the base class in addition to its own class.

 

Syntax is,

 

 

class derivedclassname :  visibilitymode baseclassname

{           // members of derivedclass    };

 

25. What is protected derivation?

 

In case of protected derivation, the protected members of the baseclass become protected members of the derived class. The public members of the base class also become the protected members of the derived class.

 

A member is declared as protected is accessible by the member functions within its.

 

26. Define multiple inheritance.

 

A single derived class is derived from more than one base classes is called multiple inheritance.

 

Syntax:

 

class derivedclassname : visibilitymode baseclass1, visibilitymode baseclass2

{

body of the derivedclass               }

27. Define multipath inheritance or virtual baseclass.

 

This form of inheritance derives a new class by multiple inheritance of baseclasses which are derived earlier from the baseclass is known as multipath inheritance.

 

It involves more than one form of inheritance namely multilevel, multiple and

 

28.                        What is Generic function? Or Define function template

A generic function defines a general set of operations that will be applied to

 

various types data. The type of data that the function will operate upon is passed to it as a parameter. Through a generic function, a single general procedure can be applied to a wide range of data.

 

A generic function is created using the keyword „template

 

General format:

Template <class T type>ret_type function name(arg list)

{

body of function

}

 

note : T type is a place holder name for a data type used by the function.

 

29. Define generic classes?

 

Using generic classes, we can create a class that defines all the algorithms used

 

by the class. The actual type of data being manipulated will be specified as a parameter when objects of that class are created

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Object Oriented Programming(OOP) : Advanced Programming : Important Short Questions and Answers: OOP - Advanced Programming |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

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