C++ OOPs Concepts | Set 4
31. Which of the following is a static polymorphism mechanism?
a) Function overloading
b) Operator overloading
c) Templates
d) All of the mentioned
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.
32. 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
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.
33. Which of the following is not a type of inheritance?
a) Multiple
b) Multilevel
c) Distributive
d) Hierarchical
Answer: C
Explanation: Distributive is not a type of inheritance whereas others are a type of inheritance having their own meaning.
34. 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
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.
35. 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
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.
36. Which members are inherited but are not accessible in any case?
a) Private
b) Public
c) Protected
d) Both private and protected
Answer: A
Explanation: Private members of a class are inherited to the child class but are not accessible from the child class.
37. 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
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.
38. 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
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.
39. 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
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.
40. 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
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).