100% found this document useful (1 vote)
120 views

OOP With C - Practical Assessment

1. The document contains a 10 question practice sessional test on OOP concepts in C++ including exceptions, virtual functions, pure virtual functions, friend functions, and class friendship. 2. The questions cover topics such as exception handling, what code should go in a try block, virtual function behavior, abstract classes, friend function access, and how class friendship works. 3. Answers to the questions are in multiple choice format with options A through D.

Uploaded by

Govind Tripathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
120 views

OOP With C - Practical Assessment

1. The document contains a 10 question practice sessional test on OOP concepts in C++ including exceptions, virtual functions, pure virtual functions, friend functions, and class friendship. 2. The questions cover topics such as exception handling, what code should go in a try block, virtual function behavior, abstract classes, friend function access, and how class friendship works. 3. Answers to the questions are in multiple choice format with options A through D.

Uploaded by

Govind Tripathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

PRACTICAL SESSIONAL TEST

OOP WITH C++ - TCS 307


Max Time - 20 Minutes

1 - What should be output of the following program?

#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";
}

cout << "After catch n";


return 0;
}

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

3 - Output of following program


#include<iostream>
using namespace std;

class Base {};


class Derived: public Base {};
int main()
{
Derived d;
try {
throw d;
}
catch(Base b) {
cout<<"Caught Base Exception";
}
catch(Derived d) {
cout<<"Caught Derived Exception";
}
return 0;
}

A​ - Caught Derived Exception


B​ - Caught Base Exception
C​ - Compiler Error
D​ - No Output

4 - Output of the following program?

#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

5 - Which of the following is true about virtual functions in C++?

A​ - Virtual functions enable compile-time polymorphism in a inheritance hierarchy


B​ - Virtual functions are functions that can’t be overridden in derived class
C​ - If a function is 'virtual' in the base class, the most-derived class's implementation of the
function is called according to the actual type of the object referred to, regardless of the
declared type of the pointer or reference. In non-virtual functions, the functions are called
according to the type of reference or pointer.
D​ - We don’t need Virtual functions for compile-time polymorphism in a inheritance
hierarchy

6 - Which of the following is true about pure virtual functions?


1) Their implementation is not provided in a class where they are declared.
2) If a class has a pure virtual function, then the class becomes an abstract class and an
instance of this class cannot be created.

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

8 - Predict the output of the following program.

#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

9 - If a function is a friend of a class, which one of the following is wrong?


A​ - A function can only be declared a friend by a class itself.
B​ - Friend functions are not members of a class, they are associated with it.
C​ - It can have access to all members of the class, even private ones.
D​ - Friend functions are members of a class

10 - Which one of the following is correct, when a class grants friend status to another
class?

A​- Class friendship is reciprocal to each other.


B​ - The member functions of the class generating friendship can access the members of the
friend class.
C​ - There is no such concept.
D​ - All member functions of the class granted friendship have unrestricted access to the
members of the class granting the friendship.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy