1. What will happen when introduce the interface of classes in a run-time polymorphic hierarchy?
A. Separation of interface from implementation
B. Merging of interface from implementation
C. Separation of interface from debugging
D. Merging of interface from debugging
Answer: A
Explanation:
: Separation of interface from implementation introduce the interface of classes in a run-time polymorphic hierarchy.
2. Which classes are called as mixin?
A. Represent a secondary design
B. Classes express functionality which represents responsibilities
C. Standard logging stream
D. Represent a priary design
Answer: B
Explanation:
: A class that expresses functionality rather than its primary design role is called a mixin.
3. What is the use of clog?
A. Standard logging stream
B. Error stream
C. Input stream
D. output stream
Answer: A
Explanation:
: clog is an object of class ostream that represents the standard logging stream. It is associated with the cstdio stream stderr, like cerr.
4. What will be the output of the following C++ code?
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
stringstream mys(ios :: in | ios :: out);
std :: string dat("The double value is : 74.79 .");
mys.str(dat);
mys.seekg(-7, ios :: enD.;
double val;
mys >> val;
val = val*val;
mys.seekp(-7,ios::enD.;
mys << val;
std :: string new_val = mys.str();
cout << new_val;
return 0;
}
A. 5593.54
B. Error
C. Runtime error
D. 5463.54
Answer: A
Explanation:
: In this program, We have used the string hierarchy to compute the square of the number.
5. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Base
{
public:
Base(){}
~Base(){}
protected:
private:
};
class Derived:public Base
{
public:
Derived(){}
Derived(){}
private:
protected:
};
int main()
{
cout << "The program exceuted" << endl;
}
A. The program executed
B. Error
C. Runtime error
D. program exceuted
Answer: B
Explanation:
: We are allowed to overload constructor but in this case as both the constructor have no parameters which implies that both the constructor have same signature which is not allowed i.e. constructors can be overloaded but two overloaded constructors can not have same function signature.
6. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class MyException
{
public:
MyException(int value) : mValue(value)
{
}
int mValue;
};
class MyDerivedException : public MyException
{
public:
MyDerivedException(int value, int anotherValue) : MyException(value), mAnotherValue(anotherValue)
{
}
int mValue;
int mAnotherValue;
};
void doSomething()
{
throw MyDerivedException(10,20);
}
int main()
{
try
{
doSomething();
}
catch (MyDerivedException &exception)
{
cout << "\nCaught Derived Class Exception\n";
}
catch (MyException &exception)
{
cout << "\nCaught Base Class Exception\n";
}
return 0;
}
A. Caught Base Class Exception
B. Caught Derived Class Exception
C. Caught Base & Derived Class Exception
D. Caught Base Class
Answer: B
Explanation:
: As we are throwing the value from the derived class, it is arising an exception in derived class
7. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s = "a long string";
s.insert(s.size() / 2, " * ");
cout << s << endl;
return 0;
}
A. a long* string
B. a long st*ring
C. Depends on compiler
D. a long string
Answer: C
Explanation:
: In this program, We are placing the string based on the size of the string and it is a string hierarchy.
8. How many types of guarantees are there in exception class can have?
A. 1
B. 2
C. 3
D. 4
Answer: C
Explanation:
: There are three types of guarantees in c++. They are weak, strong and no-throw.
10. What does the cerr represent?
A. Standard error stream
B. Standard logging stream
C. Input stream
D. Output stream
Answer: D
Explanation:
: cerr is an object of class ostream that represents the standard error stream. It is associated with the cstdio stream stderr.