We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 8
KHARAT ACADEMY :
“Subject - Object Orien ed Programming using C++ (OOP -
(IMP Questions with Answers)
AIOE
_ IScheme - MSBTE
Branch: Information Technology (CO/CM/CW/IF)
(Weightage - 18 Marks)
TT)
1. Define class and object.
OR »
Whatis a class? Give its example. KY
- *y
ey
Class: Class is a user defined data type tha éSmbined data’and functions together. It
is a collection of objects of similar type. \
Example: >
class Student YS
{
int rollno;
char name[10]; ,
public:
void getdata( );
te
b ty, Jens
%
Object: It is’abasic Tun, time entity that represents a person, place or any item that
the program hasten
f
2. Write ‘properties of static member function.
useing)”
i)/A static member function can have access to only other static data members and
“»/ functions declared in the same class.
if) A static member function can be called using the class name with a scope resolution
operator instead of object name as follows: class_name::function_name;
3. Write any two characteristics of destructor.
Answer:
Characteristics:
1) It is used to destroy objects created by a constructor.
2) Name of destructor and name of the class is same.
eriKHARAT ACADEMY
3) Its name is preceded with tilde (~) symbol.
4) Itnever takes any argument.
4. Give output for following code:
class student
int roll no;
char name [14];
}s[6];
void mainQ)
{
cout< objects belonging to that class use the same member functions, no
séparate space is allocated for member functions.
ay When the’ “objects are created only space for member variable is allocated
& } \ separe ly f for each object.
5) Se ar memory locations for the objects are essential because the member
“ep les will hold different data values for different objects this is shown in fig:
to objects ofc
5. Describe how memory is allocated XY of class with suitable diagram.KHARAT ACADEMY
Common for elt objects 1
| meiner function 1
| ete
| rembar function 2
| aa es mamory eroated wren
L ee funetiom defined
Objet 1 Object? Object 9
member variable 1 momber variable 4 member varisbio t
r
[ lea
member variable 2 pmomeanes meenbar variabin 2
tl
6. Describe use of static data me!
Answer:
Use of static data member:
1) Static data member is used to main' lues common to the entire class.
2) Itis initialized to zero when the first object of its class is created.
3) Only one copy of that member is created for the entire class and is shared by all
the objects of that class.)
4) Example: Re, ep
#include\, “Ye,
“e.
*e
#include, %
classtest “
staticint count;
Sint objno; >”
A, Public,
4 “wgvoidgetdata)
1
7" * obj_no=++count;
4 cout<<"\n Object number="<>x; } friend void swap(A,B);
class B
{
int y; public: void accept()
cout<<"\n Enter the value for y:";
cin>>y;
} friend void swap(A,B);
h
void swap(A a,B b)
{
cout<<"\n Before swapping:";
cout<<"\n Value for x="< parameter.
6) When ,obj" objectis ‘created for class ABC, parameterized constructor will invoke
and sent Nan muwill be initialized with the value 10 which is ean as an
1) When a class is declared, a constructor can be declared inside the class to
“Gnitialize data members.
2) When a base class contains a constructor with one or more arguments then it is
mandatory for the derived class to have a constructor and pass arguments to the
base class constructor.
3) When both the derived and base classes contain constructors, the base
constructor is executed first and then the constructor in the derived class is
executed.
Mime erKHARAT ACADEMY
4) The constructor of derived class receives the entire list of values as its arguments
and passes them on to the base constructors in the order in which they are
declared in the derived class.
5) General form to declare derived class constructor:
Derived-constructor (arglist1, arglist (D)):Base1 (arglist1)
Body of derived class constructor
6) Derived constructor declaration contains two parts separated with colon (
7) First part provides declaration of arguments that are passed to the derive
constructor and second part lists the function calls to the base constructors. ”
~\ Sy
Example:
#include
#include
class base
{
int x;
public:
base(int a)
{
x=a;
}
Lb
class derived: publicbase”™
t5 Sy
>
“dnt yn
vic
4 “derived (int aint b):base(a)
eh,
cout<<"Constructor in derived.y="<