C++ Programming MCQ - OOPS Concept
11. Which of the following provides a reuse mechanism?
A. Abstraction
B. Inheritance
C. Dynamic binding
D. Encapsulation
View Answer
Ans : B
Explanation: Inheritance provides a reuse mechanism.
12. What is the output of this program?
#include <iostream>
using namespace std;
class course
{
int member;
public : int* lfc()
{
return & member;
}
};
main()
{
course s;
int *ptr=s.lfc();
return 0;
}
A. This code is good to go
B. This code may result in undesirable conditions
C. This code will generate error
D. This code violates encapsulation
View Answer
Ans : D
Explanation: This code violates the encapsulation. By this code we can get the address of the private member of the class, hence we can change the value of private member, which is against the rules.
13. In a class, encapsulating an object of another class is called
A. Encapsulation
B. Inheritance
C. Composition
D. None of the above
View Answer
Ans : C
Explanation: In simple word, if a class contains an object of another class as a data member, then it is known as composition.
14. Which of the following is true about the following program
#include <iostream>
using namespace std;
class course
{
char name[10];
public : void lfc()
{
cout<< name;
}
};
A. This maintains encapsulation
B. This code does not maintain encapsulation
C. This code is vulnerable
D. This code gives error
View Answer
Ans : A
Explanation: This code maintains encapsulation. Here the private member is kept private. Outside code can't access the private members of class. Only objects of this class will be able to access the public member function at maximum.
15. A private function of a derived class can be accessed by the parent class.
A. TRUE
B. FALSE
C. May Be
D. Can't Say
View Answer
Ans : B
Explanation: If private functions get accessed even by the parent class that will violate the rules of private members. If the functions can be accessed then the derived class security is hindered.
16. Reusability is a desirable feature of a language as it
A. Decreases the testing time
B. Reduces the compilation time
C. Lowers the maintenance cost
D. Both A and C
View Answer
Ans : D
Explanation: Reusable code is an already used code, as the name implies. Hence it is bug-free and pre-tested.
There is no need to test it.
17. Which of the following operators cannot be overloaded ?
A. Static function
B. Virtual function
C. Const function
D. Operator function
View Answer
Ans : D
Explanation: None
18. Which one of the following options is correct about the statement given below? The compiler checks the type of reference in the object and not the type of object.
A. Inheritance
B. Polymorphism
C. Abstraction
D. Encapsulation
View Answer
Ans : B
Explanation: None.
19. Which of the following correctly describes overloading of functions?
A. Virtual polymorphism
B. Transient polymorphism
C. Ad-hoc polymorphism
D. Pseudo polymorphism
View Answer
Ans : C
Explanation: None
20. How many loops are there in C++ 98?
A. 2
B. 3
C. 4
D. 5
View Answer
Ans : B
Explanation: for, while & do-while loops are available
Also check :
Discussion