Beruflich Dokumente
Kultur Dokumente
An object is an extension of the class construct whose default access privilege is public.
The term object is just another way of referring to the public data members of a class.
An object is an initialized class variable.
A class is an initialized object variable.
If we have
class card {
public:
int s;
};
card a;
card* p;
we can use _________ to access int s:
p.s
a.s
p -> int
a -> s
An object is _____________ of a class.
an instance
an interface
an encapsulation
a member function
1. this pointer
(A) implicitly points to an object.
(B) can be explicitly used in a class.
(C) can be used to return an object.
(D) All of the above.
2. Data members which are static
(A) cannot be assigned a value
(B) can only be used in static functions
(C) cannot be defined in a Union
(D) can be accessed outside the class
3. How many constructors can a class have?
(A) 0 (B) 1
(C) 2 (D) any number
4. A copy constructor takes
cout<<v.rno;
}
A - 10
B - Garbage
C - Runtime error
D - Compile error
11.What does your class can hold?
a) data
b) functions
c) both a & b
d) none of the mentioned
12.
Which is used to define the member of a class externally?
a) :
b) ::
c) #
d) none of the mentioned
e) View Answer
13.Which of the following is a valid class declaration?
a) class A { int x; };
b) b) class B { }
c) c) public class A { }
d) object A { int x; };
14. Constructors are used to
a) initalize the objects
b) b) construct the data members
c)
both a & b
a) public
b) private
c) protected
d) Both b & c
215
d)
217
17. What is the output of the program?
#include <iostream>
using namespace std;
class Rect
{
int x, y;
public:
void set_values (int,int);
int area ()
{
return (x * y);
}
};
void Rect::set_values (int a, int b) {
x = a;
y = b;
}
int main ()
{
Rect recta, rectb;
recta.set_values (5, 6);
rectb.set_values (7, 6);
cout << "recta area: " << recta.area();
cout << "rectb area: " << rectb.area();
return 0;
}
a) recta area: 30 rectb area: 42
b) recta area: 20 rectb area: 34
c)
class number
{
int i;
public:
int geti();
void puti(int j);
};
int number::geti()
{
return i;
}
void number::puti(int j)
{
i = j;
}
int main()
{
number s;
s.puti(10);
cout << s.geti( );
return 0;
}
a) 10
b) 11
c)
20
d)
22.A destructor takes
A.Zero arguments
B.Three arguments
C.One argument
D.Two arguments
23.A constructor is called whenever
A.A class is declared
B.A class is used
C.A object is declared
D.An object is used
24.Constructors are used to
A.Both
B.Construct the data members
C.Initialize the objects
D.None of These
25.In C++ a function contained within a class is called
A.A method
B.A member function
C.An operator
D.A class function
26.
22
X~() {}
X() {}~
X() ~{}
~X() {}
No
Yes
28.Every class has at least one constructor function, even when none is
declared.
True
- False
29. Which of the following is a valid destructor of the class name "Country"?
29.
- int ~Country()
- void Country()
- int ~Country(Country obj)
- ~Country()
30.
class Example{
public: int a,b,c;
Example(){a=b=c=1;} //Constructor 1
Example(int a){a = a; b = c = 1;} //Constructor 2
Example(int a,int b){a = a; b = b; c = 1;} //Constructor 3
Example(int a,int b,int c){ a = a; b = b; c = c;} //Constructor 4
}
In the above example of constructor overloading, the following statement will call
which constructor
Example obj = new Example (1,2,3.3);
Options
- Constructor 2
- Constructor 4
- Constrcutor 1
- Type mismatch error
30.If a member needs to have unique value for all the objects of that same
class, declare the member as
-
31.Which type of data member retains and has unique value for all the objects
of that same class?
-
this
friend
static
both a and b
c. static
d. default
33.Is it mandatory to invoke/call a constructor for creating an object?
a. Yes
b. No
If default constructor is not defined, then how the objects of the class will be
created?
a. The compiler will generate error
b. Error will occur at run-time.
c. Compiler provides its default constructor to build the object
d. None of these
4. Which of the followings are true about constructors?
34.
The most common operation used in constructors is
A.
addition
B.
overloading
C.
assignment
D.
polymorphism
35.The dot operator (or class member access operator) connects the
following two entities (reading from left to right):
A.
B.
C.
D.
36.If you want to use a class to define objects in many different programs,
you should define the class in a C++ _____ file
A.
header
B.
program
C.
source
D.
text
B.
one for the void functions and one for the other functions
C.
one for the public data and one for the private data
D.
one for the primary functions and one for the auxiliary functions
38.
A blueprint for creating an object in C++ is called _____
A.
a class
B.
an instance
C.
a map
D.
a pattern
E.
a sketch