C++ Test Questions Set 3

1)   Public data members and member functions of the class are accessible ONLY to the member functions of that class.

a. True
b. False


Answer  Explanation 

ANSWER: False

Explanation:
No explanation is available for this question!


2)    Only functions of the class can access the data of the class and they(functions) provides the interface between data, objects and the program. This kind isolation of the data from direct access by the program is called _______________ .


a. Data Abstraction
b. Data Hiding
c. Data Binding
d. Data Encapsulation
Answer  Explanation 

ANSWER: Data Hiding

Explanation:
No explanation is available for this question!


3)   A Constructor that does not have any parameters is called____________ Constructor.

a. Custom
b. Dynamic
c. Static
d. Default
Answer  Explanation 

ANSWER: Default

Explanation:
No explanation is available for this question!


4)   If we have object from ofstream class, then default mode of opening the file is _____ .

a. ios::in
b. ios::out
c. ios::in|ios::trunc
d. ios::out|ios::trunk
Answer  Explanation 

ANSWER: ios::out|ios::trunk

Explanation:
No explanation is available for this question!


5)    _______________ is a member function that is declared within a base class and redefined by derived class.

a. virtual function
b. static function
c. friend function
d. const member function
Answer  Explanation 

ANSWER: virtual function

Explanation:
No explanation is available for this question!


6)   Syntax for Pure Virtual Function is ______________ .

a. virtual void show()==0
b. void virtual show()==0
c. virtual void show()=0
d. void virtual show()=0
Answer  Explanation 

ANSWER: virtual void show()=0

Explanation:
No explanation is available for this question!


7)   Logical expressions produce ____________ type results.

a. explicit
b. garbage
c. bool
d. static
Answer  Explanation 

ANSWER: bool

Explanation:
No explanation is available for this question!


8)   We can initialize a value of static variable of a class only when its object is created. No other initialization is permitted.

a. True
b. False


Answer  Explanation 

ANSWER: False

Explanation:
No explanation is available for this question!


9)   When a base class is privately inherited by the derived class, then_____________ .

a. protected members of the base class become private members of derived class
b. public members of the base class become private members of derived class
c. both a and b
d. only b
Answer  Explanation 

ANSWER: both a and b

Explanation:
No explanation is available for this question!


10)   What is the difference between protected and private access specifiers in inheritance?

a. private member is not inheritable and not accessible in derived class.
b. protected member is inheritable and also accessible in derived class.
c. Both are inheritable but private is accessible in the derived class.
d. Both are inheritable but protected is not accessible in the derived class.
Answer  Explanation 

ANSWER: protected member is inheritable and also accessible in derived class.

Explanation:
No explanation is available for this question!


11)   A friend function does not have 'this' pointer associated with it.

a. True
b. False


Answer  Explanation 

ANSWER: True

Explanation:
No explanation is available for this question!


12)   In nested try blocks, if both inner and outer catch handlers are not able to handle the exception, then ______________ .


a. Compiler executes only executable statements of main().
b. Compiler issues compile time errors about it.
c. Program will be executed without any interrupt.
d. Program will be terminated abnormally.
Answer  Explanation 

ANSWER: Program will be terminated abnormally.

Explanation:
No explanation is available for this question!


13)   Throwing an unhandled exception causes standard library function then _________ to be invoked.

a. stop()
b. aborted()
c. terminate()
d. Abandon()
Answer  Explanation 

ANSWER: terminate()

Explanation:
No explanation is available for this question!


14)   In CPP, it is mandatory and must to initialize const variables.

a. True
b. False


Answer  Explanation 

ANSWER: True

Explanation:
No explanation is available for this question!


15)   When a class is defined inside any function or block, it is called ___________ .

a. Nested class
b. Block class
c. Local class
d. It is not possible
Answer  Explanation 

ANSWER: Local class

Explanation:
No explanation is available for this question!


16)   Which of the followings are false statements about Local class?

1. A local class type name can only be used in the enclosing function
2. All the methods of Local classes must be defined inside the class only
3. A Local class can contain static data members.
4. A Local class may contain static functions.
5. Non-static variables of the enclosing function are not accessible inside local classes.
6. Local classes cannot access global types, variables and functions.


a. Only 1,3
b. Only 3, 6
c. Only 2 , 4 , 6
d. None of these
Answer  Explanation 

ANSWER: Only 3, 6

Explanation:
No explanation is available for this question!


17)   Due to ios::trunc mode, the file is truncated to zero length.

a. True
b. False


Answer  Explanation 

ANSWER: True

Explanation:
No explanation is available for this question!


18)   A const object of a class can call non-const member function of the class.

a. True
b. False


Answer  Explanation 

ANSWER: False

Explanation:
No explanation is available for this question!


19)   If an argument to a function is declared as const, then _______ .

a. function can modify the argument.
b. Function can’t modify the argument.
c. const argument to a function is not possible.
d. None of these
Answer  Explanation 

ANSWER: Function can’t modify the argument.

Explanation:
No explanation is available for this question!


20)   Return type of uncaught_exception() is ________________ .

a. int
b. bool
c. char *
d. double
Answer  Explanation 

ANSWER: bool

Explanation:
No explanation is available for this question!


21)   Can we write throw clause inside catch handler?

a. Yes
b. No


Answer  Explanation 

ANSWER: Yes

Explanation:
No explanation is available for this question!


22)   Default values for a function are specified when ____ .

a. function is defined
b. function is declared
c. Both a and b
d. None of these
Answer  Explanation 

ANSWER: function is declared

Explanation:
No explanation is available for this question!


23)   Can member functions of one class be friend functions of another class?

a. Yes
b. No


Answer  Explanation 

ANSWER: Yes

Explanation:
No explanation is available for this question!


24)   Predict the output:

float x= 3.1496;
cout << setpricision(2) << x;



a. 3.14
b. 3.15
c. 3.00
d. None of these
Answer  Explanation 

ANSWER: None of these

Explanation:
No explanation is available for this question!


25)   In case of binary operator overloading with member function, which of following statement should be taken into consideration?

a. Right hand operand must be object.
b. Left hand operand must be object.
c. Both the operands must be objects.
d. All of these should be considered.
Answer  Explanation 

ANSWER: Left hand operand must be object.

Explanation:
No explanation is available for this question!