1. |
Which of the followings is/are automatically added to every class, if we do not write our own? |
A. | Copy Constructor |
B. | Assignment Operator |
C. | A constructor without any parameter |
D. | All of the above |
Answer» D. All of the above |
2. |
When a copy constructor may be called? |
A. | When an object of the class is returned by value. |
B. | When an object of the class is passed (to a function) by value as an argument. |
C. | When an object is constructed based on another object of the same class |
D. | All of the above |
Answer» D. All of the above |
3. |
Constructors have _____ return type. |
A. | void |
B. | char |
C. | int |
D. | no |
Answer» D. no |
4. |
Implicit return type of a class constructor is: |
A. | not of class type itself |
B. | class type itself |
C. | a destructor of class type |
D. | a destructor not of class type |
Answer» B. class type itself |
5. |
Which of the following is true about constructors?
|
A. | All 1, 2, and 3 |
B. | Only 1 and 3 |
C. | Only 1 and 2 |
D. | Only 2 and 3 |
Answer» B. Only 1 and 3 |
6. |
Output of following program?
|
A. | Compiler Error |
B. | Runtime Error |
C. | Constructor called |
D. | None of the above |
Answer» A. Compiler Error |
7. |
#include<iostream>
|
A. | Compiler Error |
B. | Constructor called Constructor called |
C. | Constructor called |
D. | None of the above |
Answer» C. Constructor called |
8. |
Which operator is having the highest precedence? |
A. | postfix |
B. | unary |
C. | shift |
D. | equality |
Answer» D. equality |
9. |
Which of the following is FALSE about references in C++? |
A. | References cannot be NULL |
B. | A reference must be initialized when declared |
C. | Once a reference is created, it cannot be later made to reference another object; it cannot be reset. |
D. | References cannot refer to constant value |
Answer» D. References cannot refer to constant value |
10. |
Which of the following functions must use reference? |
A. | Assignment operator function |
B. | Copy Constructor |
C. | Destructor |
D. | Parameterized constructor |
Answer» B. Copy Constructor |
11. |
Output of following C++ program?
|
A. | x = 20; ref = 30 |
B. | x = 20; ref = 20 |
C. | x = 10; ref = 30 |
D. | x = 30; ref = 30 |
Answer» A. x = 20; ref = 30 |
12. |
What is the difference between struct and class in C++? |
A. | All members of a structure are public and structures don’t have constructors and destructors |
B. | Members of a class are private by default and members of struct are public by default. When deriving a struct from a class/struct, default access-specifier for a base class/struct is public and when deriving a class, default access specifier is private. |
C. | All members of a structure are public and structures don’t have virtual functions |
D. | All of the above |
Answer» B. Members of a class are private by default and members of struct are public by default. When deriving a struct from a class/struct, default access-specifier for a base class/struct is public and when deriving a class, default access specifier is private. |
13. |
Predict the output of following C++ program.
|
A. | A non-zero value |
B. | 0 |
C. | Compiler Error |
D. | Runtime Error |
Answer» A. A non-zero value |
14. |
class Test {
|
A. | 0 |
B. | Garbage Value |
C. | Compiler Error |
D. | None |
Answer» C. Compiler Error |
15. |
Which of the following is true? |
A. | All objects of a class share all data members of class |
B. | Objects of a class do not share non-static members. Every object has its own copy. |
C. | Objects of a class do not share codes of non-static methods, they have their own copy |
D. | None of the above |
Answer» B. Objects of a class do not share non-static members. Every object has its own copy. |
16. |
A member function can always access the data in __________, (in C++). |
A. | the class of which it is member |
B. | the object of which it is a member |
C. | the public part of its class |
D. | the private part of its class |
Answer» A. the class of which it is member |
17. |
Which of the following is not correct for virtual function in C++? |
A. | Must be declared in public section of class. |
B. | Virtual function can be static. |
C. | Virtual function should be accessed using pointers. |
D. | Virtual function is defined in base class. |
Answer» B. Virtual function can be static. |
18. |
Which of the following is not correct (in C++)?
|
A. | (1) |
B. | (2), (4) |
C. | (2), (3), (4) |
D. | (4) |
Answer» C. (2), (3), (4) |
19. |
Which of the following cannot be passed to a function in C++? |
A. | Constant |
B. | Structure |
C. | Array |
D. | Header file |
Answer» D. Header file |
20. |
Which of the following, in C++, is inherited in a derived class from base class? |
A. | Constructor |
B. | Destructor |
C. | Data members |
D. | Virtual methods |
Answer» C. Data members |
21. |
Which of the following is a correct statement? |
A. | Composition is a strong type of association between two classes with full ownership. |
B. | Composition is a strong type of association between two classes with partial ownership. |
C. | Composition is a weak type of association between two classes with partial ownership. |
D. | Composition is a weak type of association between two classes with strong ownership. |
Answer» A. Composition is a strong type of association between two classes with full ownership. |
22. |
Which of the following is not a correct statement? |
A. | Every class containing abstract method must be declared abstract. |
B. | Abstract class can directly be initiated with ‘new’ operator. |
C. | Abstract class can be initiated. |
D. | Abstract class does not contain any definition of implementation. |
Answer» B. Abstract class can directly be initiated with ‘new’ operator. |
23. |
When a method in a subclass has the same name and type signatures as a method in the superclass, then the method in the subclass _____ the method in the superclass. |
A. | Overloads |
B. | Friendships |
C. | Inherits |
D. | Overrides |
Answer» D. Overrides |
24. |
It is possible to define a class within a class termed as nested class. There are _____ types of nested classes. |
A. | 2 |
B. | 3 |
C. | 4 |
D. | 5 |
Answer» A. 2 |
25. |
When one object reference variable is assigned to another object reference variable then |
A. | a copy of the object is created. |
B. | a copy of the reference is created. |
C. | a copy of the reference is not created. |
D. | it is illegal to assign one object reference variable to another object reference variable. |
Answer» B. a copy of the reference is created. |
We're developing a website for study materials for students.
We would love to hear your answers to some of the questions.