Which members are inherited but are not accessible in any case?
Protected
Both private and protected
Public
Private
Answer and explanation
Private members of a class are inherited to the child class but are not accessible from the child class.
ObjectiveMcq
Print Protected
This page is protected for print. Use the website to view the content.
Which members are inherited but are not accessible in any case?
Protected
Both private and protected
Public
Private
Private members of a class are inherited to the child class but are not accessible from the child class.
Which of the following statement is true?
Both I and II
I only
Neither I nor II
II only
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.
What happens if a class does not have a name?
It will not have a destructor
It will neither have a constructor or destructor
It will not have a constructor
It is not allowed
No explanation is available for this question yet.
Which of the following is not a type of inheritance?
Multilevel
Multiple
Hierarchical
Distributive
Distributive is not a type of inheritance whereas others are a type of inheritance having their own meaning.
Which of the following is true?
I only
Both I and II
II only
Neither I nor II
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.
Which of the following is a static polymorphism mechanism?
Operator overloading
Templates
All of the mentioned
Function overloading
All the options mentioned above uses static polymorphism mechanism. As the conflicts in all these types of functions are resolved during compile-time.
Which of the following supports the concept that reusability is a desirable feature of a language?
It decreases the compilation time
It reduces maintenance cost
It reduced both testing and maintenance time
It reduces the testing time
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.
Which of the following is correct?
C++ allows dynamic type checking.
C++ allows both static and dynamic type checking
C++ allows static member function to be of type const.
C++ allows static type checking
C++ allows both static and dynamic type checking i.e. types are checked by the compiler.
Which concept is used to implement late binding?
Virtual functions
Operator functions
Static functions
Constant functions
Virtual functions are used to implement the concept of late binding i.e. binding actual functions to their calls.
Which of the following cannot be used with the virtual keyword?
Constructors
Destructors
Class
Member functions
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.
Which operator is overloaded for a cout object?
<
<<
cout in C++ uses << operator to print anything so << operator is overloaded for a cout object.
In how many ways we can handle errors in any class?
2
1
3
4
As the variable is containing the information about the float value val = 5.5 therefore the container is not empty therefore the program outputs “Var is not Empty”.
What is the use of reset() function?
Used to destroys the contained object in any variable
Used to change the object any container is holding
Used to empty any container value
Used to check the type of any variable
has_value() function is provided to check whether a given any container is empty or not.
What is the use of has_value() function in any container?
Used to return the type information about the any container
Used to destroys the contained object in any variable
Used to check whether any container is empty or not
Used to change the object any container is holding
The type function is used to get information about the data stored in the any container variable. name() attribute is used to print the type id of the data. Now as the data stored in any variable is float therefore the program outputs f as f is the type id for float.
What will be the output of the following C++ code
#include<iostream>
#include<any>
using namespace std;
int main()
{
float val = 5. any var(val);
cout<<var.type().name()<<endl;
return}
Pkc
f
d
u
type() function is used to check the type of data/value the container object is holding.
What is the use of type() function in any container?
Used to change the object any container is holding
Used to return the type information about the any container
Used to check whether a container is empty or not
Used to destroys the contained object in any variable
In this program we are using emplace() function to change the any variable contents and this is allowed in C++ therefore the program runs fine.
What is the use of emplace() function?
Used to check the type of any variable
Used to add more item to the any list
Used to empty any container value
Used to change the object any container is holding
emplace() function is used to change the object contained in any container i.e destroying the present object and creating the new object for the value given by the user.
Which exception is thrown if the typecasting is not done properly?
type_mismatched
bad_any_cast
bad_cast_mismatched
bad_type_cast
bad_any_cast exception is thrown when typecasting is not done properly by the user i.e. if any is storing int value and we are trying to cast it into a string then the program will throw bad_any_cast exception.
What happens when both of the following C++ programs are compiled and executed
===== Program 1 =====
#include <iostream>
#include <array>
using namespace std;
int main()
{
array<int,arr arr1.fill(5);
cout<<get<5>(arr1);
return}
=====================
===== Program 2 =====
#include <iostream>
#include <array>
using namespace std;
int main()
{
array<int,arr arr1.fill(5);
cout<<arr1.at(5);
return}
=====================
Program 1 gives run-time error and Program 2 gives compile-time error
Both programs results into compile-time error
Both programs results into run-time error
Program 1 gives compile-time error and Program 2 gives run-time error
fill() function sets the value of each element equal to the value passed as parameter to the function.
What will be the output of the following C++ code
#include <iostream>
#include <array>
using namespace std;
int main(int argc, char const *argv[])
{
array<int,arr arr1.fill(5);
cout<<get<5>(arr1);
return}
Compile-time error
Run-time error
Segmentation fault
5
fill() function is used to fill an array class with the given single value.