OOP With C - Practical Assessment
OOP With C - Practical Assessment
#include <iostream>
using namespace std;
int main()
{
int x = -1;
try {
cout << "Inside try n";
if (x < 0)
{
throw x;
cout << "After throw n";
}
}
catch (int x ) {
cout << "Exception Caught n";
}
A - Inside try
Exception Caught
B - Inside try
Exception Caught
After catch
C - Inside try
After throw
After catch
D - Inside try
Exception Caught
After catch
lock?
2 - What should be put in a try b
1. Statements that might cause exceptions
2. Statements that should be skipped in case of an exception
A - Only 1
B - Only 2
C - 1 and 2 Both
D - None
#include <iostream>
using namespace std;
int main()
{
try
{
throw 'a';
}
catch (int param)
{
cout << "int exceptionn";
}
catch (...)
{
cout << "default exceptionn";
}
cout << "After Exception";
return 0;
}
A - int exception
After Exception
B - default exception
After Exception
C - int exception
D - default exception
A - Only 1
B - Only 2
C - Both 1 and 2
D - Neither 1 nor 2
7 - Predict the output of the following C++ program.
#include <iostream>
using namespace std;
class A
{
public:
virtual void fun();
};
class B
{
public:
void fun();
};
int main()
{
int a = sizeof(A), b = sizeof(B);
if (a == b) cout << "a == b";
else if (a > b) cout << "a > b";
else cout << "a < b";
return 0;
}
A - a == b
B - a < b
C - a > b
D - Compile Time
#include <iostream>
using namespace std;
class A
{
protected:
int x;
public:
A() {x = 0;}
friend void show();
};
class B: public A
{
public:
B() : y (0) {}
private:
int y;
};
void show()
{
A a;
B b;
cout << "The default value of A::x = " << a.x << " ";
cout << "The default value of B::y = " << b.y;
}
A - Compiler Dependent
B - The default value of A::x = 0 The default value of B::y = 0
C - Compiler Error in show() because y is private in class b
D - Compiler Error in show() because x is protected in class A
10 - Which one of the following is correct, when a class grants friend status to another
class?