Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Code continued…..

OUTPUT

Enter value of a is: 5

Value of a is 5
Output

This is child class


POLYMORPHISM
Question -1 : Write a short note on polymorphism.
 Polymorphism means the ability to take more than one form.
 It allows a single name to be used for more than one related purpose.
 It means ability of operators and functions to act differently in different
situations.
Type of polymorphism are

Compile time polymorphism:


It is function overloading and operator overloading
Functions overloading
It is the practice of declaring the same function with different signatures.

Operator overloading

Like + performs addition of two integers , also strings same way an operator is
made to work totally different when used with objects of time class.
Dynamic binding(Late binding)

Virtual Function

3. This pointer with example

#include<iostream> sample()
Using namespace std; { a=10;}
Class Sample void disp(int a)
{ int a; { cout<<”The value of argument a =”<<a;
Public: cout<<”\n The value of data member
a=”<<this->a; }};
Int main()
{ sample s;
s.disp(20);
return 0; }
Output :
The value of argument of a = 20
The value of data member a = 10
5. Explain virtual function with example.

Rule for virtual function


Example:

Output :
Base class pointer assign address of base class object
Simple function in base class
Virtual function of base class
Base class pointer assign address of derived class object
Simple function in base class
Same name with virtual function of base class in derived class.
7. Explain pure virtual functions

Syntax
Virtual void display()=o OR virtual void display(){}
TEMPLATES
1. Explain function and class templates with appropriate example.
Example:

Class Template :
2. Exceptional handling. Explain how to handle an exception with
appropriate example.
In programming two most common types of error are logical error and
syntax error.
The syntax error is detected during compilation of program , logical error
will detect during execution of program. So it is difficultto handle logical
error.
Exceptional handling provides mechanism for handling logical errors.
Steps:
When the value of b is zero at that time exception will throw and this exception will catch in
catch block and print the message value is zero.
Write notes on STL.

Components of STL
There are 3 components of STL as follows
Container

Algorithm

Iterator

You might also like