Anda di halaman 1dari 10

What is the difference between an object and a class?

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

(A) no argument (B) one argument


(C) two arguments (D) arbitrary no. of arguments
5. What purpose do classes serve?
A. data encapsulation
B. providing a convenient way of modeling real-world objects
C. simplifying code reuse
D. all of the above
6. Which is not a protection level provided by classes in C++?
A. protected
B. hidden
C. private
D. public
7. What value must a destructor return?
A. A pointer to the class.
B. An object of the class.
C. A status code determining whether the class was destructed correctly
D. Destructors do not return a value.
8. Which of the following is a valid class declaration?
A. class A { int x; };
B. class B { }
C. public class A { }
D. object A { int x; }; 5. Which functions will every class contain?
A. None
B. Constructor
C. Destructor
D. Both a constructor and a destructor
9. How many number of arguments can a destructor of a class receives?
A-0
B-1
C-2
D - None of the above.
10.What is the output of the following program?
#include<isotream>

using namespace std;


main()
{
class student
{

int rno = 10;


} v;

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

d) none of the mentioned


15. Which of these following members are not accessed by using direct
member access operator?

a) public
b) private
c) protected
d) Both b & c

16. What is the output of the following program?


#include <iostream>
using namespace std;
class Box
{
public :
double length;
double breadth;
double height;
};
int main( )
{
Box Box1;
double volume;
Box1.height = 5;
Box1.length = 6;
Box1.breadth = 7.1;
volume = Box1.height * Box1.length * Box1.breadth;
cout << "Volume of Box1 : " << volume <<endl;
return 0;
}
a) 210
b) 213
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)

recta area: 30 rectb area: 21

d) none of the mentioned


18.Pick out the other definition of objects.
a) member of the class
b) associate of the class
c) attribute of the class
d) instance of the class
19.How many objects can present in a single class?
a) 1
b) 2
c) 3
d) as many as possible
20.Which special character is used to mark the end of class?
a) ;
b) :
c) #
d) $
21.What is the output of this program?
#include <iostream>
using namespace std;

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() {}

27.The default access level assigned to members of a class is ___________


Private
Public
Protected
Needs to be assigned

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
-

Global variable outside class


Local variable inside constructor
Static variable inside class
Dynamic variable inside class

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

32.A constructor that does not have any parameters is called____________


constructor.
a. Custom
b. dynamic

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.

a class member and a class object

B.

a class object and a class

C.

a class and a member of that class

D.

a class object and a member of that class

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

37.Many programmers separate a class into two files: _____


A.

one for the declarations and one for the implementations

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

Anda mungkin juga menyukai