C++ Programming Multiple Choice Questions - OOPS Concept
This section focuses on the "OOPS Concept" in C++ programming langauge. These Multiple Choice Questions (MCQ) should be practiced to improve the C++ programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. The OOPs concept in C++, exposing only necessary information to users or clients is known as
A. Data hiding
B. Encapsulation
C. Hiding complexity
D. Abstraction
View Answer
Ans : D
Explanation: The OOPs concept in C++, exposing only necessary information to users or clients is known as Abstraction.
2. A class is made abstract by declaring at least one of its functions as?
A. abstract classes
B. pure virtual function
C. abstract functions
D. Interface
View Answer
Ans : B
Explanation: A class is made abstract by declaring at least one of its functions as pure virtual function.
3. Which is private member functions access scope?
A. Member functions which can used outside the class
B. Member functions which are accessible in derived class
C. Member functions which can only be used within the class
D. Member functions which can't be accessed inside the class
View Answer
Ans : C
Explanation: The member functions can be accessed inside the class only if they are private. The access is scope is limited to ensure the security of the private members and their usage.
4. What is the output of this program?
#include <iostream>
using namespace std;
class team
{
public : int member;
void LFC()
{
cout<<"Its base class";
};
};
class course:public team
{
public :
void LFC()
{
cout<<"Its derived class";
}
};
int main()
{
team t; course c;
t.LFC();
c.LFC();
}
A. Its base classIts derived class
B. Its base class Its derived class
C. Its derived classIts base class
D. Its derived class Its base class
View Answer
Ans : A
Explanation: You need to focus on how the output is going to be shown, no space will be given after first message from base class. And then the message from derived class will be printed. Function find() in base class overrides the function of base class being derived.
5. C++ was originally developed by
A. Sir Richard Hadlee
B. Clocksin and Mellish
C. Donald E. Knuth
D. Bjame Stroustrup
View Answer
Ans : D
Explanation: C++ was originally developed by Bjame Stroustrup.
6. What is the output of this program?
#include <iostream>
using namespace std;
class course
{
char name[10];
public : void LFC()
{
cout<<"Its course system";
}
};
class team : public course
{
public: void LFC()
{
cout<<"Its team course system";
}
};
int main()
{
team t;
t.LFC();
}
A. Its team course system
B. Its course system
C. Its team course systemIts course system
D. Its course systemIts team course system
View Answer
Ans : A
Explanation: Notice that the function name in derived class is different from the function name in base class. Hence when we call the find() function, base class function is executed. No polymorphism is used here.
7. 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.
8. 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.
9. 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.
10. 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.
11. 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.
12. 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.
13. Which of the following access specifier is used as a default in a class definition?
A. Private
B. Public
C. Friend
D. Protected
View Answer
Ans : A
Explanation: Private access specifier is used as a default in a class definition.
14. Not using virtual destructor feature in a C++ object oriented programing can cause
A. An Issue in creating object of the class
B. Memory leak
C. An issue in calling base class destructor
D. None of the above
View Answer
Ans : B
Explanation: Virtual destructor is used to maintain the hierarchy of destructor calls for polymorphic classes in inheritance. If we don't use it then it may cause resource leak or memory leak.
15. If private member functions are to be declared in C++ then __________
A. private(private member list)
B. private
C. private:
D. private :-
View Answer
Ans : C
Explanation: The private members doesn't have to have the keyword with each private member. We only have to specify the keyword private followed by single colon and then private member's are listed.
16. The order in which operands are evaluated in an expression is predictable if the operator is
A. Addition
B. Modulus
C. Multiply
D. &&
View Answer
Ans : D
Explanation: The order in which operands are evaluated in an expression is not defined by the language and is compiler-dependent. For example, pop ( ) - pop ( ) may do (current top stack) - (the data just below the current top), or vice-versa, depending on which pope ) call is executed first.
However, the order of evaluation for the operator & & is defined by the language. It evaluates from left to right. Do not confuse order of evaluation with associativity.
17. Which of the following is a mechanism of static polymorphism?
A. Templates
B. Function overloading
C. Operator overloading
D. All of the above
View Answer
Ans : D
Explanation: Function overloading is a mechanism of static polymorphism.
18. IS A relationship in C++ is
A. Inheritance
B. Encapsulation
C. Composition
D. None of the above
View Answer
Ans : A
Explanation: IS A relationship in C++ is Inheritance.
19. Can main() function be made private?
A. Yes, always
B. Yes, if program doesn't contain any classes
C. No, because main function is user defined
D. No, never
View Answer
Ans : D
Explanation: The reason given in c option is wrong. The proper reason that the main function should not be private is that it should be accessible in whole program. This makes the program flexible.
20. At what point of time a variable comes into existence in memory is determined by its
A. Data type
B. Storage class
C. Scope
D. All of the above
View Answer
Ans : B
Explanation: a variable comes into existence in memory is determined by its Storage class.
21. Which of the following concepts is used to implement late binding?
A. Static function
B. Virtual function
C. Const function
D. Operator function
View Answer
Ans : B
Explanation: None
22. For Cat and Animal class, correct way of inheritance is
A. Class Cat: public Animal
B. Class Animal: public Cat
C. Both are correct way
D. None is correct way
View Answer
Ans : A
Explanation: None
23. 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
24. 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.
25. 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
26. 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
27. 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
28. 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