Important Questions For Class 12 Computer Science (C++) - Object Oriented Programming - Learn CBSE
Important Questions For Class 12 Computer Science (C++) - Object Oriented Programming - Learn CBSE
RD
(ii)SHARMA
Inheritance JEE MAIN CLASS 12 CLASS 11 CLASS 10 CLASS 9 NCERT SOLUTIONS
(iii) Polymorphism
(iv) Data
CBSE abstraction
SAMPLE PAPERS LAKHMIR SINGH
Example of Inheritance
Inheritanc
Class Rectangle
{
::::
};
class Area : public Rectangle
{
::::
};
Question 2:
Explain data hiding with an example. All India 2014C
Answer:
Data hiding is a property, where internal data structure of an object is hidden from the outside world. Data
hiding helps to secure the data. It is implemented with private and protected keywords. ,
e.g.
class Item
{
private:
int item_no;
float item_cost;
public:
RD SHARMA
void getdata(); JEE MAIN CLASS 12 CLASS 11 CLASS 10 CLASS 9 NCERT SOLUTIONS
void putdata();
}; CBSE SAMPLE PAPERS LAKHMIR SINGH
Here, in this example variables item_no and item_cost are hidden, i.e. cannot be directly accessed from
outside the class Item.
Question 3:
What is function overloading? Give an example in C++ to illustrate function overloading.
All India 2014,2009
or
What do you understand by function overloading? Give an example illustrating its use in a C++ program. All
India 2009
Answer:
When several functions have same name but performing different tasks, then it is known as function
overloading. The de nitions of these functions are differentiable by the number or types of their arguments.
e.g.
{
return(0.5*b*h);
CBSE SAMPLE PAPERS LAKHMIR SINGH
}
Question 4:
Write the output of the following C++ code. Also, write the name of feature of Object Oriented Programming
used in the following program jointly illustrated by the functions [I] to [IV]. Delhi 2011
#include<iostream.h>
void Print() //Function[I]
{
for(int K=1; K<=60; K++)
cout<<"-";
cout<<endl;
}
void Print(int N) //Function[II]
{
for(int K=1; K<=N; K++)
cout<<"*";
cout<<endl;
}
void Print(int A, int B)//Function[III]
}
for(int K=1; K<=B; K++)
cout<<A*K;
cout<<endl;
}
RD SHARMA
void JEE int
Print(char T, MAINN)//Function[IV]
CLASS 12 CLASS 11 CLASS 10 CLASS 9 NCERT SOLUTIONS
{
for(int K=l; K<=N;
CBSE SAMPLE PAPERSK++) LAKHMIR SINGH
cout<<T;
cout<<endl;
}
void main!)
{
int U=9, V=4, W=3;
char C= '@';
Print(C, V);
Print(U, W);
}
Answer:
Feature of C++→ Function overloading The output will be:
@@@@
91827
Question 5:
Write the output of the following C++ code. Also, write the name of feature of Object Oriented Programming
used in the following program jointly illustrated by the functions [I] to [IV]: All India 2011
#include<iostream.h>
void Lined //Function[I]
{
for(int L=1;L<=80;L++)