Unit 2(OOPs C++ ) Sem2

                     

Theory

Quiz 1

When the base class is publicly inherited, public members of the base class become …………. of the derived class.
private members
protected members
Public members
Not inherited

Public members

In ……………….. inheritance, the base classes are constructed in the order in which they appear in the deceleration of the derived class.
multipath
multiple
multilevel
hierarchical

multiple

If 2 classes derive one base class and redefine a function of base class, also overload some operators inside class body. Among these two things of function and operator overloading, where is polymorphism used?
Function overloading only
Operator overloading only
Both of these are using polymorphism
Either function overloading or operator overloading because polymorphism can be applied only once in a program

Either function overloading or operator overloading because polymorphism can be applied only once in a program

In case of using abstract class or function overloading, which function is supposed to be called first?
Local function
Function with highest priority in compiler
Global function
Function with lowest priority because it might have been halted since long time, because of low priority

Function with highest priority in compiler


Quiz 2

The output of following program

#include<iostream>
using namespace std;
class Base
{
public:
    virtual void show() { cout<<" In Base n"; }
};
class Derived: public Base
{
public:
    void show() { cout<<"In Derived n"; }
};
int main(void)
{
    Base *bp, b;
    Derived d;
    bp = &d;
    bp->show();
    bp = &b;
    bp->show();
    return 0;
}


a) In Base
In Base
b) In Base
In Derived
c) In Derived
In Derived
d) In Derived
In Base

d) In Derived
In Base

……………. binding means that an object is bound to its function call at compile time.
late
static
dynamic
fixed

static

A …………………. refers to an object that that currently invokes a member function.
void pointers
null pointers
this pointer
base pointer

this pointer

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 abstract class and an instance of this class cannot be created.
Both 1 and 2
Only 1
Only 2
Neither 1 nor 2

*pending


Surprise Test

State whether the following statements about inheritance are True or False.
i) A public member of a class can be accessed by its own objects using the dot operator.
ii) While inheriting, the private members of the base class will never become members of its derived class.
True, False
False, True
True, True
False, False

True, True

A derived class with only one base class is called …………… inheritance.
single
multiple
multilevel
hierarchical

single

A member declared as ………….. is accessible by the member functions within its class and any class immediately derived from it.
protected
private
public
friend

protected

The friend functions and the member functions of a friend class can directly access the ………………. data.
private and protected
private and public
protected and public
private, protected and public

private and protected

False statements about function overloading is
Defining multiple functions with same name in a class is called function overloading
Overloaded function must differ in their order and types of arguments.
Overloaded functions should be preceded with virtual keyword
No statement is false

Overloaded functions should be preceded with virtual keyword

Compile time polymorphism in C++ language are
Operator overloading
Function overloading
Function overriding
A & B

A & B

Which among the following can’t be used for polymorphism?
Static member functions
Member functions overloading
Predefined operator overloading
Constructor overloading

Static member functions

Run time polymorphism is achieved only when a ……………….. Is accessed through a pointer to the base class.
static function
Real function
Member function
Virtual function

Virtual function

The pointer to a function is known as …………………. function.
forward
pointer
callback
backward

callback

When VTABLE (Virtual table) get created for a class?
Every class by default has virtual table
When a Class Overrides the function of Base class
When a class contains at least one virtual function.
When a class is derived from a base class.

When a class contains at least one virtual function.

Which concept is not available in C++?
Virtual constructor
Virtual destructor
Virtual function
Virtual Table

Virtual constructor

The output of following program is

#include<iostream>
using namespace std;
class Base
{
public:
    virtual void show() { cout<<" In Base n"; }
};
class Derived: public Base
{
public:
    void show() { cout<<"In Derived n"; }
};
 int main(void)
{
    Base *bp, b;
    Derived d;
    bp = &d;
    bp->show();
    bp = &b;
    bp->show();
    return 0;
}


a) In Base
In Base
b) In Base
In Derived
c) In Derived
In Derived
d) In Derived
In Base

d) In Derived
In Base


Practical

Pre

When the inheritance is private, the private methods in base class are __ in the derived class (in C++)
Inaccessible
Accessible
Protected
Public

Inaccessible

What is meant by multiple inheritance?
Deriving a base class from derived class
Deriving a derived class from base class
Deriving a derived class from more than one base class
None of the mentioned

Deriving a derived class from more than one base class

Can we pass parameters to base class constructor though derived class or derived class constructor?
Yes
No
May Be
Can’t Say

Yes

Which symbol is used to create multiple inheritance?
Dot
Comma
Dollar
None of the above

Comma

Functions that can be inherited from base class in C++ program
Constructor
Destructor
Static function
None

None

Which of the following shows multiple inheritances?
A->B->C
A->B; A->C
A,B->C
B->A

A,B->C

How access specifiers in Class helps in Abstraction?
They does not helps in any way
They allows us to show only required things to outer world
They help in keeping things together
Abstraction concept is not used in classes

They allows us to show only required things to outer world

Out of the following, which is not a member of the class?
Static function
Friend function
Constant function
Virtual function

Friend function

What is the other name used for functions inside a class?
Member variables
Member functions
Class functions
Class variables

Member functions

Which of the following approach is used by C++?
Top-down
Bottom-up
Left-right
Right-left

Bottom-up

The __, also known as the address operator, returns the memory address of a variable.
asterisk (* )
ampersand ( & )
percent sign ( % )
exclamation point ( ! )

ampersand ( & )

A function may return a pointer but the programmer must ensure that the pointer
still points to a valid object after the function ends
has not been assigned an address
was received as a parameter by the function
has not previously been returned by another function

still points to a valid object after the function ends

What does the following statement do?
double *num2;
Declares a double variable named num2
Declares and initializes a pointer variable named num2
Initializes a pointer variable named num2
Declares a pointer variable named num2

Declares a pointer variable named num2

Use the delete operator only on pointers that were
never used
not correctly initialized
created with the new operator
dereferenced inappropriately

created with the new operator

In C++, the __ keyword was introduced to represent address 0.
nullptr
NULL
weak_ptr
shared_ptr

nullptr


Post

Which among the following is best to define hierarchical inheritance?
More than one classes being derived from one class
More than 2 classes being derived from single base class
At most 2 classes being derived from single base class
At most 1 class derived from another class

More than one classes being derived from one class

Which class uses hierarchical inheritance in following code?

class A
{
int a;
};
class B:class A
{
int b;
};
class C:class A,class B
{
int c;
};
class D:class A
{
int d;
};


Class A, B, C
Class B, C, D
Class A, C, D
Class A, D, B

Class A, D, B

Which among the following is correct for following code?

#include <iostream>
using namespace std;
class A{
      public: int a=10;
      void disp()
      {
        cout<<"in base class";
      }
};
class B:public A
{
      public: void dis()
      {
            cout<<a;
      }
};
int main()
{
      B b;
      b.disp();
      return 0;
}


Compile time error
Runtime error
Program runs and o/p is 10
Program runs and o/p is “in base class”

Program runs and o/p is “in base class”

Hierarchical inheritance can be a subset of _____
Hybrid inheritance
Multiple inheritance
Single level inheritance
Multilevel inheritance

Hybrid inheritance

What does polymorphism in OOPs mean?
Concept of allowing overriding of functions
Concept of hiding data
Concept of keeping things in different modules/files
Concept of wrapping things into a single unit

Concept of allowing overriding of functions

Which of the following explains Polymorphism?
a) int func(int, int);
float func1(float, float);
b) int func(int);
int func(int);
c) int func(float);
int func(int, int, char);
d) int func();
int new_func();

c) int func(float);
int func(int, int, char);

Which of the following feature of OOPs is not used in the following C++ code?

Which of the following feature of OOPs is not used in the following C++ code?
class A
{
int i;
public:
void print(){cout<<"hello"<<i;}
}
class B:public A
{
int j;
public:
void assign(int a)
{
j = a;
}
}


Abstraction
Encapsulation
Inheritance
Polymorphism

Polymorphism

How run-time polymorphisms are implemented in C++?
Using Inheritance
Using Virtual functions
Using Templates
Using Inheritance and Virtual functions

Using Inheritance and Virtual functions

How compile-time polymorphisms are implemented in C++?
Using Inheritance
Using Virtual functions
Using operator overloading
Using Inheritance and Virtual functions

Using operator overloading

Assuming ptr is a pointer variable, what will the following statement output?
cout<< ptr; the value stored in the variable whose address is contained in ptr the string “ptr”
the address of the variable whose address is stored in ptr
the address of the variable stored in ptr

the value stored in the variable whose address is contained in ptr

Which of the following statements displays the address of the variable numb?
cout<< numb; cout<< *numb; cin>>&numb;
cout<<&numb;

cout<<&numb;

Which of the following statements deletes memory that has been dynamically allocated for an array?
int array = delete memory;
int delete[ ];
delete [] array;
new array = delete;

delete [] array;

A pointer variable is designed to store
any legal C++ value
only floating-point values
an integer
a memory address

a memory address

Dynamic memory allocation occurs
when a new variable is created by the compiler
when a new variable is created at runtime
when a pointer fails to dereference the right variable
when a pointer is assigned an incorrect address

when a new variable is created at runtime


* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first.


Explore Latest Progies