C++ Programming MCQ – OOPs

This set of C++ Programming Multiple Choice Questions & Answers (MCQs) focuses on “OOPs”.

1. Wrapping data and its related functionality into a single entity is known as _____________
a) Abstraction
b) Encapsulation
c) Polymorphism
d) Modularity
View Answer

Answer: b
Explanation: In OOPs, the property of enclosing data and its related functions into a single entity(in C++ we call them classes) is called encapsulation.

2. How structures and classes in C++ differ?
a) In Structures, members are public by default whereas, in Classes, they are private by default
b) In Structures, members are private by default whereas, in Classes, they are public by default
c) Structures by default hide every member whereas classes do not
d) Structures cannot have private members whereas classes can have
View Answer

Answer: a
Explanation: Structure members are public by default whereas, class members are private by default. Both of them can have private and public members.

3. What does polymorphism in OOPs mean?
a) Concept of allowing overiding of functions
b) Concept of hiding data
c) Concept of keeping things in differnt modules/files
d) Concept of wrapping things into a single unit
View Answer

Answer: a
Explanation: In OOPs, Polymorphism is the concept of allowing a user to override functions either by changing the types or number of parameters passed.
advertisement
advertisement

4. Which concept allows you to reuse the written code?
a) Encapsulation
b) Abstraction
c) Inheritance
d) Polymorphism
View Answer

Answer: c
Explanation: Inheritance allows you to reuse your already written code by inheriting the properties of written code into other parts of the code, hence allowing you to reuse the already written code.

5. Which of the following explains Polymorphism?
a)

Note: Join free Sanfoundry classes at Telegram or Youtube
int func(int, int);
float func1(float, float);

b)

advertisement
int func(int);
int func(int);

c)

advertisement
int func(float);
float func(int, int, char);

d)

 int func();
int new_func();
View Answer
Answer: c
Explanation: Polymorphism means overriding the same function by changing types or number of arguments. So we have only two options which has the same function names, but as one can observe that in one option types, name and number of parameters all are same which will lead to an error. Hence that is wrong so the option having same name and different types or number of parameters is correct.
 
 

6. Which of the following shows multiple inheritances?
a) A->B->C
b) A->B; A->C
c) A,B->C
d) B->A
View Answer

Answer: c
Explanation: In multiple inheritance, a single class is inherited from two classes. So in A,B->C, Class C is inherited from A and B, whereas in A->B->C, C from B and B from A called simple inheritance, in A->B; A->C, B and C are inherited from A which is called hierarchical inheritance.

7. How access specifiers in Class helps in Abstraction?
a) They does not helps in any way
b) They allows us to show only required things to outer world
c) They help in keeping things together
d) Abstraction concept is not used in classes
View Answer

Answer: b
Explanation: Abstraction is the concept of hiding things from the outer world and showing only the required things to the world, which is where access specifiers private, protected and public helps in keeping our knowledge hidden from the world.

8. C++ is ______________
a) procedural programming language
b) object oriented programming language
c) functional programming language
d) both procedural and object oriented programming language
View Answer

Answer: d
Explanation: C++ supports both procedural(step by step instruction) and object oriented programming(using concept of classes and objects).

9. What does modularity mean?
a) Hiding part of program
b) Subdividing program into small independent parts
c) Overriding parts of program
d) Wrapping things into single unit
View Answer

Answer: b
Explanation: Modularity means dividing a program into independent sub programs so that it can be invoked from other parts of the same program or any other program.

10. Which of the following feature of OOPs is not used in the following C++ code?

class A
{
    int i;
    public:
    void print(){cout<<"hello"<<i;}
}
 
class B: public A
{
    int j;
    public:
    void assign(int a){j = a;}
}

a) Abstraction
b) Encapsulation
c) Inheritance
d) Polymorphism
View Answer

Answer: d
Explanation: As i and j members are private i.e. they are hidden from outer world therefore we have used the concept of abstraction. Next data members and there related functions are put together into single class therefore encapsulation is used. Also as class B is derived from A therefore Inheritance concept is used. But as no function is overloaded in any of the classes therefore, the concept of polymorphism is missing here.

More MCQs on C++ OOPs Concept:

Sanfoundry Global Education & Learning Series – C++ Programming Language.

To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.