MABS Institution
11th Computer Science Monthly Test - 3 ( Inheritance )-Aug 2020
-
-
-
-
-
-
-
-
-
-
Which symbol inheritance?
Dot
Comma
Dollar
At the rate of
-
Overriding of the members are resolved by using_________.
.
;
: :
this
-
Which of the following are extended in the order of inherited class?
data members
destructors
member functions
constructors
-
When a derived class inherits from multiple base classes is known as
Multilevel
Multiple
Hierarchical
Hybrid
-
When classes are inherited with all the visibility modes but derived class cannot access the
private members
protected members
public members
both a and b
-
Shadowing functions-resolved using__________.
dot operator
scope resolution operator
membership operator
comma operator
-
Which of the following is a constant pointer holds the memory address of the current object?
size of ()
this pointer
pointer
dot pointer
-
The derived class may inherit the properties of the base class based on its ________
access specifier
visibility mode
members
function
-
Which of the following statement is true or false?
(i) The derived class constructors are executed first
(ii) Derived class cannot inherit the base class constructor.
(iii) In multiple inheritance, the constructor start executing from right to left.
(iv) In multilevel inheritance, the constructors exerted in the order of inheritance(i) false, (ii) false, (iii) false: (iv) true
(i) false, (ii) true, (iii) false, (iv) false
(i) false, (ii) false, (iii) true, (iv) true
(i) false, (ii) true, (iii) false, (iv) true
-
Which of the following is the correct syntax of inheritance?
Class derived class name : base Class name {define class body};
Class base class name ; derived class name {define class body};
Class derived class name : access base class name {define class body};
Class base class name ; access derived class name {define class body};
-
Which of the following is used to refere the current objects members?
pointers
members
this pointer
: :
-
If single inheritance is used, program will contain
Atleast - 2 classes
At most 2 classes
Exactly 2 classess
Atmost 4 classess
-
The accessibility of base class by the derived class is controlled by__________
access specifiers
visibility modes
data members
member functions
-
The private members of base class can be accessed indirectly by the derived class by using base class public or protected.
data members
access specifiers
member functions
visibility mode
-
Match the following
(i) 1) Multiple Inheritance (ii) 2) Hybrid inheritance (iii) 3) Single Inheritance (iv) 4) Hierarchical Inheritance (v) 5) Multilevel Inheritance 5, 3,2, 1,4
3,5,2, 1,4
3,5,4, 1,2
3,5,1,4,2
-
Inheritance is process of creating new class from
Base class
abstract
derived class
Function
-
Answer the following table
if base class access specifier is And a Base class member is Then, the derived class member access is Private Private (i) (ii) Private Protected (iii) (1) no access, (ii) Pnvate, (iii) Public
(i) no access, (ii) Private, (iii) Private
(i) no access, (ii) Public, (iii) Private
(i) no access, (ii) Public, (iii) Public
-
Class base x
tint x;
Public:
void set x (int y) {x = y;}
};
Class derived: base x { } ;
What is the access level for the member function set x in the class derived above?protected
private
public
error
-
class x
{int a;
public:
xOn
};
class y
{x x1;
public:
y(){}
};
class z : public y,x
{
int b;
public:
z(){}
}z1;
What is the order of constructor for object zl to be invoked?z,y,x,x
x,y,z,x
y,x,x,z
z,y,z
-
How many types of inheritanse are there?
3
4
5
2
-
Which type of inheritance is illustrated by the following code?·
Class student {public: int marks;};
Class topper: public student {public:char grade};
Class overage {public: int marks-needed;};
Class section :public average {public: char name
[10]};
Class overall: public average
{public: int students};single
multilevel and single
hierarchical
Hierarchical and single
-
Which of the following class is a power packed class?
sub class
child class
derived class
all of these
-
class vehicle
{ int wheels;
public:
void input_ data(float,float);
void output_data();
protected:
int passenger;
};
class heavy_vehicle : protected vehicle {
int diesel_petrol;
protected:
int load;
protected:
int load;
public:
voidread_data(float,float)
voidwrite_data(); };
class bus: private heavy_vehicle {
charTicket[20] ;
public:
void fetch_data(char);
voiddisplay_data(); };
};
The member function that is inherited as public by Class Businput_data(),
read_data(), output_data()write_data()
fetch _data()
All of these display _data()
-
Which of the following statement is true or false?
(i) When a derived class inherits from many base classes is known as multilevel inheritance
(ii) When many derived classes are created from single base class called multiple inheritance
(iii) The transitive nature of inheritance is multilevel inheritance
(iv) is an example of hierarchical inheritance.(i) false, (ii) false, (iii) true, (iv) true
(i) true, (ii) false, (iii) true, (iv) true
(i) true, (ii) false, (iii) true, (iv) false
(i) false, (ii) false, (iii) false, (iv) true
-
Which of the following principle supports transitivity?
Inheritance
Polymorphism
Encapsulation
abstraction
-
class vehicle
{ int wheels;
public:
void input_ data(float,float);
void output_data();
protected:
int passenger;
};
class heavy_vehicle : protected vehicle {
int diesel_petrol;
protected:
int load;
protected:
int load;
public:
voidread_data(float,float)
voidwrite_data(); };
class bus: private heavy_vehicle {
charTicket[20] ;
public:
void fetch_data(char);
voiddisplay_data(); };
};
Which is the base class ofthe class heavy_vehicle?Bus
heavy_vehicle
Vehicle
Both (a) and (c)
-
The combination of more than one type of inheritance is called
Hybrid inheritance
Network inheritance
Hierarchical inheritance
Distributed inheritance
-
Answer the following table
if base class access specifier is And a Base class member is Then, the derived class member access is Protected (i) No acess (ii) Protected Protected (iii) (i) Private, (ii) Public, (iii) Protected
(i) Private, (ii) Public, (iii) Public
(i) Protected, (ii) Public, (iii) Protected
(i) Private, (ii) Public, (iii) Private
-
Can a derived class get access privilege for a private member of the base class? If yes, how?
-
What do you mean by overriding?
-
Explain the uses of private, protected and public inheritance.
-
What is the difference between polymorphism and inheritance though are used for reusability of code?
-
What are the points to be noted while deriving a new class?
-
Write some facts about the execution of constructors and destructors in inheritance.
-
Write the output of the following program.//Implementation of Single Inheritance using public
visibility mode
#include < iostream >
using namespace std;
class Shape
{
private:
int count;
protected:
int width;
int height;
public:
void setWidth(int w)
{
width=w;
}
void setHeight(int h)
{
height=h;
}
};
class Rectangle: publicShape
{
public:
int getArea()
{
return (width * height);
}
};
int main()
{
Rectangle Rect;
Rect.setWidth( 5);
Rect.setHeight(7);
II Print the area of theobject.
cour<< "Total area: "<< Rect.getArea() << endl;
return ();
} -
Why do you need for inheritance?
-
Write the output of the following program.
#include< iostream >
using namespace std;
class T
{
public:
int x;
void foot()
{
x = 6; // same as this->x = 6;
this ->x = 5; // explicit use of this ->
cout<x;
}
void foo(int x) // parameter x shadows the member
with the same name
{
this->x = x; // unqualified x refers to the
parameter.'this->' required for disambiguation
cout<< endl << x <<" "<x;
}};
int main()
{
T t1,t2;
t1.foot();
t2.food();
} -
In what situation shadowing base class function inderived class arises? How will you resolve the situation?
-
What is difference between the members present in the private visibility mode and the members present in the public visibility mode