C++ Programming Questions and Answers – OOPs – 3

This set of C++ Programming Objective Questions & Answers focuses on “OOPs – 3”.

1. Which operator is overloaded for a cout object?
a) >>
b) <<
c) <
d) >
View Answer

Answer: b
Explanation: cout in C++ uses << operator to print anything so << operator is overloaded for a cout object.

2. Which of the following cannot be used with the virtual keyword?
a) Class
b) Member functions
c) Constructors
d) Destructors
View Answer

Answer: c
Explanation: Virtual keyword cannot be used with constructors as constructors are defined to initialized an object of particular class hence no other class needs constructor of other class.

3. Which concept is used to implement late binding?
a) Virtual functions
b) Operator functions
c) Constant functions
d) Static functions
View Answer

Answer: a
Explanation: Virtual functions are used to implement the concept of late binding i.e. binding actual functions to their calls.
advertisement
advertisement

4. Which of the following is correct?
a) C++ allows static type checking
b) C++ allows dynamic type checking.
c) C++ allows static member function to be of type const.
d) C++ allows both static and dynamic type checking
View Answer

Answer: d
Explanation: C++ allows both static and dynamic type checking i.e. types are checked by the compiler.

5. Which of the following supports the concept that reusability is a desirable feature of a language?
a) It reduces the testing time
b) It reduces maintenance cost
c) It decreases the compilation time
d) It reduced both testing and maintenance time
View Answer

Answer: d
Explanation: As we will be using the existing code therefore we don’t need to check the code again and again so testing and maintenance time decreases but the compiler time may increase or remains same because though we are reusing the code but every part needs to be compiled and extra include statement needs to be executed therefore compilation time may remain same or increases.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. Which of the following is a static polymorphism mechanism?
a) Function overloading
b) Operator overloading
c) Templates
d) All of the mentioned
View Answer

Answer: d
Explanation: All the options mentioned above uses static polymorphism mechanism. As the conflicts in all these types of functions are resolved during compile-time.

7. Which of the following is true?
I) All operators in C++ can be overloaded.
II) The basic meaning of an operator can be changed.
a) I only
b) II only
c) Both I and II
d) Neither I nor II
View Answer

Answer: d
Explanation: Both statements are false because all the operators of C++ cannot be overloaded and the basic meaning of an operator cannot be changed, we can only give new meaning to an operator.
advertisement

8. Which of the following is not a type of inheritance?
a) Multiple
b) Multilevel
c) Distributive
d) Hierarchical
View Answer

Answer: c
Explanation: Distributive is not a type of inheritance whereas others are a type of inheritance having their own meaning.

9. What happens if a class does not have a name?
a) It will not have a constructor
b) It will not have a destructor
c) It is not allowed
d) It will neither have a constructor or destructor
View Answer

Answer: b
Explanation: A class without a name will not have a destructor. The object is made so constructor is required but the destructor is not. Check the code below:

advertisement
#include <iostream>
using namespace std;
class
{
    public:
	void func()
        {
		cout<<"Hello world";
	}
}a;
int main(int argc, char const *argv[])
{
	a.func();
	return 0;
}

10. Which of the following statement is true?
I) In Procedural programming languages, all function calls are resolved at compile-time
II) In Object Oriented programming languages, all function calls are resolved at compile-time
a) I only
b) II only
c) Both I and II
d) Neither I nor II
View Answer

Answer: a
Explanation: In Procedural programming like C we don’t have the concept of polymorphism, therefore, all the function calls are resolved at the compile-time but in case of OOP languages sue to polymorphism concept all function calls are not resolved at compile-time.

11. Which members are inherited but are not accessible in any case?
a) Private
b) Public
c) Protected
d) Both private and protected
View Answer

Answer: a
Explanation: Private members of a class are inherited to the child class but are not accessible from the child class.

12. Which of the following is correct?
a) Friend functions can access public members of a class
b) Friend functions can access protected members of a class
c) Friend functions can access private members of a class
d) All of the mentioned
View Answer

Answer: d
Explanation: Friend functions can access any member of a class without caring about the type of member i.e. without caring whether it is private, protected or public.

13. Which of the following is correct in C++?
a) Classes cannot have protected data members
b) Structures can have member functions
c) Class members are public by default
d) Structure members are private by default
View Answer

Answer: b
Explanation: Though C does not allows member functions in structures but C++ allows structures to have member functions. Members of structures are public by default and those of classes are private by default. Classes can have protected data members.

14. Which of the following is used to make an abstract class?
a) By using virtual keyword in front of a class declaration
b) By using an abstract keyword in front of a class declaration
c) By declaring a virtual function in a class
d) By declaring a pure virtual function in a class
View Answer

Answer: d
Explanation: Abstract class should have at least one pure virtual function. Therefore to declare an abstract class one should declare a pure virtual function in a class.

15. Which of the following is correct?
a) A class is an instance of its objects
b) An object is an instance of its class
c) A class is an instance of the data type that the class have
d) An object is an instance of the data type of the class
View Answer

Answer: b
Explanation: An object is an instance of a class i.e. an object represents a class i.e. what class has(data members) and what it can do(member functions).

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.