CBSE - MCQ Question Banks (के. मा. शि. बो . -प्रश्नमाला )

PreviousNext

Q. 190201 When does a copy constructor is called ?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION


1.  When an object is created and initialized with another object, as shown in the example below -
 

     INFO Y(X);                  

     Here, class is INFO, Y is the object being created and X is the object being used to initialize it.
 

2.  When an object is passed by value to a function. 

func(ob);    - function call, an object being passed

3.  When a function returns an object.  

      ABC func2( );  -  prototype of a function that returns an object of class ABC

      ob = func2( ); -  function call          


Q. 190202 A constructor can be declared under private as well as public section. How will it affect the accessibility to objects? Discuss.
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

A constructor obeys all the access rules.   When declared under private, it will be available to other members of the class only.  Thus, member functions can declare objects.  The same also applies to friend functions as they can also access private members of a class. 

 

When they are declared under public, they can be accessed in outside functions too. 


Q. 190203 How does a constructor can be called?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

The constructor may be called implicitly or explicitly - 

 

Implicit Call to the Constructor – Here, the constructor is not called by name but is invoked automatically.  It initializes the object with the passed values.

Example : for a class named INFO, the statement below will implicitly call the constructor.

                 INFO X(12,’A’);

 

Explicit Call to the Constructor – Here, the constructor is called by name to initialize the object with the passed values.

Example : for a class named INFO, the statement below will explicitly call the constructor.

                 INFO Y=INFO(12,'A');

 

Here, the object created is Y and the constructor is explicitly called to initialize it with the values 12 and ‘A’.


Q. 190204 How does a constructor with default values works like a default constructor? Illustrate it with an Example. 
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

The default constructor doesn't accept any arguments.  However, the class can have a constructor with  default arguments too.  In case values are not provided while creating the object, the constructor with default values can provide values.

 

Example -

 

class ABC{

     int a;

     int b;

   public:

     void show(){

        cout<<"A = "<< a<<"B = "<< b;

     }

    ABC( ){a=123;b=345; }                     //default constructor

    ABC(int x=55, int y=88){a=x; b=y;}  // constructor with default arguments.   

};

void main(){

  ABC ob;                    //default constructor called ? or one with default arguments?

  ob.show();

}

 

Here, the object ob is being created and arguments are not passed, so the default constructor should be invoked.  However, the constructor with default values can also be called as it provides values for missing arguments.  In this example, to create object ob, both default and the constructor with default values can be called.  This is actually an ambiguous situation and should be avoided.


Q. 190205 State the important characteristics of constructors?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

Constructors are special member functions.  Their characteristics are – 


 
1.  Same name as the class

 2.  Invoked automatically when objects are created

 3.  Return type is not specified for constructors

 4   Constructors cannot be static

 5.  Constructors cannot be inherited

 6.  Normally the constructor is called implicitly but it can be called explicitly too.

         


Q. 190206 An object of a derived class (which itself is derived from another class)


A. can access private members of base class.

B. can access protected members of base class.

C. cannot access private or protected members of base class.

D. cannot access public members of base class.

Right Answer is: C

SOLUTION

The private members of the base class are never accessible outside the class. The protected members of the base class are accessible only to the derived classes.


Q. 190207 The size of a derived class object is equal to


A. the size of data members in the base class.

B. the size of data members in the derived class.

C. the sum of sizes of data members in base class and the derived class.

D. 20 bytes always.

Right Answer is: C

SOLUTION

Derived class inherits all the properties of base class and add some features of its own.


Q. 190208 The declaration statement “ class xyitem: private item, private sales” indicates that


A. the class sales and item has been derived from class xyitem.

B. the class sales has been derived from two classes, xyitem and item.

C. the class xyitem and item has been derived from class sales.

D. the class xyitem has been derived from two classes, item and sales.

Right Answer is: D

SOLUTION

xyitem is a subclass, derived from item and sales.


Q. 190209 A class of which we can not create objects


A. Base class

B. Derived class

C. Abstract class

D. Extended class

Right Answer is: B

SOLUTION

Abstract class is a class which is served as a base class only. It is not possible to create object of abstract class.


Q. 190210 The derived class constructor is responsible for invoking


A. the base class constructor.

B. the base class members.

C. the abstract class.

D. the friend function.

Right Answer is: A

SOLUTION

The derived class constructor is responsible for invoking( and passing arguments to) the base class constructor.


Q. 190211 When we add new refinements in the derived class, then


A. the derived class automatically changes its name.

B. the base class is deleted.

C. the base class remains unchanged.

D. these changes are reflected in the base class too.

Right Answer is: C

SOLUTION

The process of creating new class, called derived class, from the existing old one, called base class, is known as inheritance. The derived classes inherit all the properties of base class and can add features of its own.


Q. 190212 When a class contains objects of other types as its member, it is referred to as


A. containership.

B. polymorphism.

C. inheritance.

D. encapsulation.

Right Answer is: A

SOLUTION

Creation of an object that contains another object is very different than the creation of an independent object. The other terms for containership are aggregation, containment, composition or nesting.


Q. 190213 When a class contains objects of another class inside it, then it is called


A. nesting of classes.

B. nesting of objects.

C. inheritance of class.

D. polymorphism of class.

Right Answer is: B

SOLUTION

In such a situation, the contained objects are constructed first and then the objects of the enclosing class are constructed.


Q. 190214 What is the advantage of inheritance?
Right Answer is:

SOLUTION

One of the main advantages is code reusability.  Once a class has been satisfactorily defined, it can be used in other classes without making changes.   It represents real world entities very effectively – class Person can have features that can be inherited by Employee as well as Student.


Q. 190215 What is inheritance ?
Right Answer is:

SOLUTION

Inheritance is one of the basic concept of Object Oriented Programming.  It is the capability of one class to inherit properties from another class.


Q. 190216 What is the difference between the two derived classes below ?  
a)  class S1 : private P
b)  class S2 : public P
Right Answer is:

SOLUTION

In the first statement, class P is inherited in private mode. Thus inheritable public and protected members of P become private members of S1.  Private members can be accessed only by other members or friends of the class, not by the objects.
In the second statement, class P is inherited in public mode. Thus inheritable public and protected members of P become members of S2, with the same accessibility.  Protected members can be accessed only by other members but the public members will be accessible by the objects. 


Q. 190217 Class A inherits from Class B.  Define a constructor for class A that takes 3 integer arguments, passes on two of these to the base class constructor and initializes its own member x with the third one.
Right Answer is:

SOLUTION

class A : public B{ int x;

 

                                …..    

                          public:

                               A( int a, int b, int c) : B(a, b)

                               { x = c;  }

                               ……..

                   };                      


Q. 190218 What do you understand by virtual base class?
Right Answer is:

SOLUTION

When a class inherits from multiple base classes, it can lead to an ambiguous situation.  This is possible when the base classes themselves are derived from a common base class. 

As shown in the figure, A is a base class from which two classes are derived, B and C.  These further act as base classes for D.

  

 

 

Let us now try to visualize the problem that can arise.  D wants to access a function which is inherited from base class A, into B and C.  Obviously, since D is inheriting from both B and C, it receives two copies of the members they inherited from their base class A.   

When this member is accessed, the compiler faces an ambiguous situation, which can be resolved in two ways. 

One way out is to call the member with the class name i.e. B :: member  or C :: member  so that it is clear which member is being accessed.

The other way is to make the common base class (here, A) virtual, as shown in the example below.

 

class A

{ ….

         public :

             int a;

};

 

class B : public virtual A

{ ….

         public :

             int b;

};

 

class C : public virtual A

{ ….

         public :

             int c;

};

 

class D : public B, public C

{ ….

         public :

             int c;

};

Now, because of the keyword virtual, classes B and C will share a single common base class member,i.e., a. Thus there will be no ambiguity when accessing it. 


Q. 190219 What is a Nested Class?  How is it different from Inheritance?
Right Answer is:

SOLUTION

When a class is defined inside another class, it is a nested class.  This is different from Inheritance.  Members of the nested class can access its other members and object of the nested class can access its public members.  Similarly, members of the outside class can access other members and the object can access public members.  We cannot say that members of one class become members of another class.  Public members of the nested class can still only be called by its objects.  If they were inherited, objects of the derived class would be able to call them too.


Q. 190220 What is the difference between IS-A and HAS-A relationship?
Right Answer is:

SOLUTION

When a class inherits from another class, the derived class has IS-A relationship with its base class. 
When a class contains object of another class-type, then containing/enclosing class has HAS-A relationship with contained/enclosed class.


Q. 190221 What is Containership?  How is it different from Inheritance?
Right Answer is:

SOLUTION

When a class contains objects of other class types as its member, it is referred to as Containership or Containment or Aggregation.  Containership is very different from Inheritance.  In Inheritance, we have a class that has its own features in addition to some features of another class.  Through Containership we can create a class containing object of another class type.


Q. 190222 Can private members of base class be inherited in the derived class?
Right Answer is:

SOLUTION

Private members cannot be inherited.  However, other member functions that access the private members  can be inherited.  Thus, private members can be indirectly accessed through inherited functions. 


Q. 190223 What do you understand by visibility modes? 
Right Answer is:

SOLUTION

Visibility modes are used to specify  how  the  features of the base class are inherited into the derived class.  The three visibility modes are  public, private and  protected.  The inheritable base class members are placed under the access specifiers  in the derived class depending on the visibility mode and its own access specifier.


Q. 190224 Name the different forms of Inheritance.
Right Answer is:

SOLUTION

The different forms of inheritance are as follows -

(i)  Single Inheritance

(ii) Multiple Inheritance

(iii) Hierarchical Inheritance

(iv) Multilevel Inheritance

(v) Hybrid Inheritance


Q. 190225 What are the errors in the given code?    #include < iostream.h>           //line1 class A{                          //line2      int a1;                         //line3    protected :                  //line4      int a2;                         //line5    public :                         //line6      int a3;                         //line7 };                                      //line8 class B : public A           //line9 {                                       //line10    public:                          //line11     void func(){               //line12      int b1,b2,b3;             //line13      b1=a1;                       //line14      b2=a2;                       //line15      b3=a3;                       //line16  }                                      //line17 };                                      //line18 class C : A                       //line19 {                                       //line20   public:                           //line21    void func(){                //line22     int c1,c2,c3;               //line23     c1=a1;                         //line24     c2=a2;                         //line25     c3=a3;                         //line26   }                                     //line27 };                                      //line28                                          //line29 void main(){                  //line30   int x,y,z;                       //line31   B ob;                              //line32   x=ob.a1;                       //line33   y=ob.a2;                       //line34   z=ob.a3;                       //line35   C oc;                              //line36   x=oc.a1;                       //line37   y=oc.a2;                       //line38   z=oc.a3;                       //line39 }                                       //line40
Right Answer is:

SOLUTION

a)  Line 14, a1 is a private member of A, so cannot be accessed
b)  Line 24, a1 is a private member of A, so cannot be accessed
c)  Line 33, a1 is a private member of A, so cannot be accessed
d)  Line 34, a2 is a protected member of B, so cannot be accessed
e)  Line 37, a1 is a private member of A, so cannot be accessed
f)   Line 38, a2 is a private member of C, so cannot be accessed
g)  Line 39, a3 is a private member of C, so cannot be accessed  


Q. 190226 Look at the following  class -              
            class A{                     public :                        int h;                        int b;            };  Using A as base class, derive two classes, Rectangle and Triangle.  Both of these should have a function calcarea() that calculates and displays the area of the rectangle or triangle, respectively.  Define parameterized constructors to initialize the values of height and base.
Right Answer is:

SOLUTION

 #include < iostream.h>

 class A{

     public :

         int h;

         int b;

};

class Rectangle : public A

{

     public:

        Rectangle(int x, int y){

             h = x;

             b = y;

        }

         void calcarea(){

            int a=h * b;

            cout<<"Area of the rectangle = "<< a;

         }

};

class Triangle : public A

{

          public:

             Triangle(int x, int y){

                  h = x;

                  b = y;

            }

            void calcarea(){

               float a=(h * b)*0.5;

               cout<<"Area of the Triangle = "<< a;

            }

};

 

void main(){

     Triangle ot(11,9);

     Rectangle or(12,8);

     ot.calcarea();

     or.calcarea();

            }                                              


Q. 190227 How are constructors and destructors handled in derived classes?
Right Answer is:

SOLUTION

As you know, constructors and destructors are not inherited.  A derived class has its own members along with inherited members.  An object of the derived class will have its own data members and  it will be built upon the data members  inherited from the base class.   To create an object, the constructor must be called.

 

If the base class has a constructor that accepts arguments (i.e. parameterized constructor) then the derived class should have a constructor that passes the arguments to the base class constructor.  If the base class has only default constructors, then the derived class need not have a constructor. 

The example below shows single inheritance in private visibility mode, where the base class constructor takes an argument.  The derived class has a constructor that invokes the base class constructor and passes on the value to it.

 

Remember, to create an object, first the constructor of the base class and then the constructor of the derived class will be called.         

 

When an object is destroyed, first the derived class destructor is invoked and then the base class destructor.   

 

 

#include < iostream.h >

class P{                                                //base class P

    int a;

  public:

      P(int x){ a=x;                                 // constructor takes 1 argument         

            cout<<"a = "<< a;

      }

     void getdat(){

            cout<<"a = ";

            cin>>a;

     }

     void dispdat(){

           cout<< a;

      }

};

 

class E : private P{                             //derived class E         

       int c;

  public:

    E(int x, int y) : P(x)                       //constructor invokes base class constructor

   { c=y; }

    void getdata(){

           cout<<"c = ";

           cin>>c;

           getdat();

    }

   void dispdata(){

           cout<< c ;

          dispdat();

   }

};

 

void main()

{

       E e(12,34);

       e.getdata();

       e.dispdata();

}

 


Q. 190228 How do visibility mode and access specifier determine the access of inherited members? 
Right Answer is:

SOLUTION

The visibility mode specifies whether features of the base class are derived publicly, privately or in protected mode.  This controls the access of the inherited members in the derived class.

 

Public visibility mode – Inheritable public members of base class become public members of the derived class and  protected  members of base class become protected members of the derived class.  Private members are not inherited.

 

Protected visibility mode - Inheritable public members  and protected  members of base class become protected members of the derived class.  Private members are not inherited.

 

Private visibility mode - Inheritable public members  and protected  members of base class become private members of the derived class.  Private members are not inherited. 
                                                                             

                                                                                              


Q. 190229 Describe the different forms of Inheritance in brief.
Right Answer is:

SOLUTION

The different forms of inheritance are

Single – When a subclass inherits from only one base class.

The syntax in single inheritance is –

class derived_class_name : visibility_mode base_class_name

{

  ……………. // members of the derived class

}

 

Multiple - When a subclass inherits from multiple base classes.

 

 

The syntax in multiple inheritance is –

class derived_class_name : visibility_mode base_class_name1, visibility_mode base_class_name2 [,visibility_mode base_class_name1,  … ]

{

  ……………. // members of the derived class

}

 

Multilevel - When a subclass inherits from a class which inherits from another class.

 

The general form of multilevel inheritance is –

class derived_class_name1 : visibility_mode base_class_name

{

  ……………. // members of the derived class

}

 

class derived_class_name2 : visibility_mode derived_class_name1  

{

  ……………. // members of the derived class

}

 

Hierarchical - When many subclasses inherit from  one base class.

 

 

The general form of  inheritance is –                                            

class derived_class_name : visibility_mode base_class_name

{

  ……………. // members of the derived class

}

 

Hybrid – A combination of 2 or more forms, like when a subclass inherits from multiple base classes and the base classes inherit from a single  base class. 

Text Box: [E K/-]

 

 

 


Q. 190230 Create a base class Building that stores the number of floors and the number of rooms the building has.  From this, derive a class Flats that stores the number of bathrooms and open terraces.  From Building, derive another class Offices that stores the number of Fire Exits.  
Right Answer is:

SOLUTION

#include< iostream.h >
class Building{
                   int floors;
                   int rooms;
              public :
                   void getd(){
                                    cout<<"nNo. of Floors = ";
                                    cin>>floors;
                                    cout<<"nNo. of Rooms = ";
                                    cin>>rooms;
                                   }
 
                   void dispd(){
                                     cout<<"nNo. of Floors = "<< floors;
                                     cout<<"nNo. of Rooms = "<< rooms;
                                   }
                   };
class Flats : public Building{
                                     int baths;
                                     int terraces;
                               public :
                                    void getdat(){
                                           getd();       
                                                        cout<<"nNo. of Bathrooms = ";
                                                        cin>>baths;
                                                        cout<<"nNo. of Terraces = ";
                                                        cin>>terraces;
                                                       }
                                    void dispdat(){    
                                          dispd();         
                                                        cout<<"nNo. of Bathrooms = "<< baths;
                                                        cout<<"nNo. of Terraces = "<< terraces;
                                                       }
                                     };
class Offices : public Building{
                                          int firexits;
                                   public : 
                                        void getdata(){
                                              getd();      
                                                             cout<<"nNo. of Fire Exits = ";
                                                             cin>>firexits;
                                                             }
                                        void dispdata(){
                                               dispd();    
                                                              cout<<"nNo. of Fire Exits = "<< firexits;
                                                             }
                                        };

void main(){
                  Flats of;
                  Offices oo;
                  of.getdat();
                  of.dispdat();
                  oo.getdata();
                  oo.dispdata();
               }


Q. 190231 Look at the code below and answer the questions that follow.
    class A{
                   void afun();
        protected :  int a1,a2;  
        public :  void getA();
                       void dispA();
                  };
class H : protected A{     
                                        int h1,h2; 
                   protected : int h3,h4;          void getH();    public:       void dispH(); }; class V : public H {       int v1;     protected :        int v2;        void getV(int);     public:          void dispV(); };   a)  Name the base class and derived class names for class H.
b)  Name all protected members of class V.
c)  Which data members  can be accessed by function getV()?
d)  Which functions can be accessed by objects of class V?    
Right Answer is:

SOLUTION

a)  Base class is A and derived class is V for class H
b)  Protected members are v2, getV(), h3,h4, getH(), a1, a2, getA(), dispA() 
c)  Function getV() can access v1, v2, h3, h4, a1,a2
d)  Objects of class V can access dispV() and dispH()


Q. 190232 Look at the code below and answer the questions that follow.     class Vehicle{        int maxspeed;    protected :        int maxseats;    public :        void getdat(int, int);        void dispdat(); }; class Heavy : protected Vehicle {     int mileage;    protected :        int load;    public:       void getd(int, int);       void dispd(); }; class Van : private Heavy {       int weight;     public:        void getdata(int);        void dispdata(); };   a)  Name the base class and derived class names for class Heavy.
b)  Which functions can be accessed by dispdata()?
c)  Which functions can be accessed by objects of class Heavy?
d)  Which functions can be accessed by objects of class Van?
Right Answer is:

SOLUTION

a)  Base class is Vehicle and derived class is Van for class Heavy
b)  Function dispdata() can access getdata(), getd(), dispd(), getdat() and dispdat()
c)  Objects of class Heavy can access getd() and dispd()
d)  Objects of class Van can access getdata() and dispdata() 


Q. 190233 The stream class to which the memory-to-file link is related, is known as


A. ifstream.

B. ofstream.

C. fstream.

D. instream.

Right Answer is: B

SOLUTION

The ofstream function provides an interface to write data to files as output streams.


Q. 190234 If visibility mode is private,


A. public and protected members become private members in the derived class

B. private, public and protected members become private, public and protected members respectively in the derived class

C. private and protected members become private members in the derived class

D. public and protected members become public and protected members respectively in the derived class

Right Answer is: A

SOLUTION

The private derivation means, the derived class can access the public and private members of the base class privately.


Q. 190235 If visibility mode is public,


A. private, public and protected members become public members in the derived class

B. public and protected members become public and protected respectively in the derived class

C. private, public and protected members are inherited under their own access labels

D. private and protected members become public and protected members respectively in the derived class

Right Answer is: B

SOLUTION

The public derivation means that the derived class can access the public and protected members of the base class but not the private members of the base class.


Q. 190236 The different visibility modes are,


A. public, personal and protected

B. personal, private and protected

C. public, private and protected

D. public, private and personal

Right Answer is: C

SOLUTION

The visibility modes controls the visibility and availability of inherited base class members in the derived class. C++ provides three types of visibility modes - public, private and protected.


Q. 190237 A class that inherits features from another class is called


A. derived class

B. base class

C. abstract class

D. nested class

Right Answer is: A

SOLUTION

A new class can be derived from an existing class. Then the new derived class is called derived class or subclass and the existing class is called base class or super class.


Q. 190238 Base class is


A. the class that contains constructors 

B. the class that contains public functions

C. the class that inherits features

D. the class from which features are inherited

Right Answer is: D

SOLUTION

A new class can be derived from an existing class. The new derived class is call derived class or subclass and the existing class is called base class or super class.


Q. 190239 ‘Transitive nature of Inheritance’  means, if class X inherits from class Y, then


A. subclasses of X will automatically inherit features of class Y

B. subclasses of X will not automatically inherit features of class Y

C. subclasses of Y will automatically inherit features of class  X

D. some subclasses of Y will inherit features of class X automatically

Right Answer is: A

SOLUTION

As X become subclass of Y, it could access features of class Y.


Q. 190240 When many subclasses inherit from a single base class, it is called:


A. Multiple inheritance

B. Multilevel inheritance

C. Hierarchical inheritance

D. Single inheritance

Right Answer is: C

SOLUTION

Hierarchical inheritance is a method of inheritance where one or more derived classes (subclasses) are derived from a common base class.


Q. 190241 When a subclass inherits a class which itself inherits from another class, it is


A. multiple inheritance

B. multilevel inheritance

C. hierarchical inheritance

D. single inheritance 

Right Answer is: B

SOLUTION

The transitive nature of inheritance is reflected by this form of inheritance. When a subclass inherits from a class that itself inherits from another class, it is known as multilevel inheritance.


Q. 190242 When one sub class inherits from multiple base classes, it is


A. multiple inheritance

B. multilevel inheritance

C. hierarchical inheritance

D. single inheritance 

Right Answer is: A

SOLUTION

When a sub class inherits from multiple base classes, it is known as Multiple Inheritance.


Q. 190243 When one subclass inherits from one base class, it is


A. multiple inheritance

B. multilevel inheritance

C. hierarchical inheritance

D. single inheritance 

Right Answer is: D

SOLUTION

When a subclass inherits only from one base class, it is known as Single Inheritance.


Q. 190244 One advantage of inheritance is


A. no access  to members

B. access to private members

C. code reusability

D. error handling

Right Answer is: C

SOLUTION

Through Inheritance features of one class could get accessed in another class.


Q. 190245 Additional features can be added to an existing class, without modifying it.  This is called -


A. Abstraction

B. Inheritance

C. Encapsulation

D. Data hiding

Right Answer is: B

SOLUTION

Inheritance is the basic feature of OOPs using which one class can inherits the properties or features of another class.


Q. 190246 Visibility mode should be protected when


A. members are to be inaccessible from outside.

B. members are to be inheritable but inaccessible from outside.

C. members are to be inherited further.

D. members are not to be inherited.

Right Answer is: B

SOLUTION

When a base class is inherited with protected visibility mode the protected and public members of the base class become protected members of the derived class.


Q. 190247 The different visibility modes are


A. public, personal and protected

B. personal, private and protected

C. public, private and protected

D. public, private and personal

Right Answer is: C

SOLUTION

public --> Inherits the protected members as protected in derived class and pubic members will be public in derived class protected --> pubic and protected members of the base class will become protected in derived class Private --> public and protected members will become private in derived class


Q. 190248 A class that inherits features of another class is known as


A. derived class

B. base class

C. abstract class

D. nested class

Right Answer is: A

SOLUTION

New classes can be derived from existing classes using a mechanism called "inheritance". The class that inherits the properties from base class is called derived class.


Q. 190249 What is the difference between private and protected members?
A. derived class
B. base class
C. abstract class
D. nested class

Right Answer is:

SOLUTION

Private members can be used by the member functions of the same class whereas Protected members could get accessed by the derived class as well.


Q. 190250 What is Abstract Class?
A. derived class
B. base class
C. abstract class
D. nested class

Right Answer is:

SOLUTION

Abstract class is used as a blueprint in C++ where declaration of data members or member functions takes place. It is serve as a base class from which other classes could get derived. Objects for abstract class are not created. 


Q. 190251 Which members are not inherited, even if they are public members of a class?
A. derived class
B. base class
C. abstract class
D. nested class

Right Answer is:

SOLUTION

The Constructors and Destructors of base class are not inherited.


Q. 190252 What type of C++ class members (data members and member functions) are not inherited?
A. derived class
B. base class
C. abstract class
D. nested class

Right Answer is:

SOLUTION

Data Members - Static data members of the base class are not inherited.

Member Functions - Constructors and Destructors of base class are not inherited.


Q. 190253 What do you understand by base class and derived class (or sub class) ?
A. derived class
B. base class
C. abstract class
D. nested class

Right Answer is:

SOLUTION

An existing class can be used to derive a new class.  The existing class, whose properties are inherited is the base class and the class that inherits features is the derived class.


Q. 190254 The syntax of defining a derived class (using single inheritance) is 


A. class derived –class-name : visibility-mode base class name{ : // members of derived class };

B. class derived –class-name ;visibility-mode base class name{ : // members of derived class };

C. class derived –class-name ; visibility-mode base class name{ ; // members of derived class };

D. class derived –class-name : { : // members of derived class };

Right Answer is: A

SOLUTION

The colon indicates that sub class is based upon the super class.


Q. 190255 The property of an object oriented language that, lets us  generate a model which is closer to the real world model is


A. polymorphism.

B. inheritance.

C. abstraction.

D. encapsulation.

Right Answer is: B

SOLUTION

Inheritance is the capability of one class to inherit the properties of another class. 
Example: class cars inherit the properties from automobiles, which itself inherited from another class vehicles.


Q. 190256 A class inherits from another class. 
In the  above statement what type of relation does exist between derived class and base class?   


A. private inheritance.

B. public inheritance.

C. protected inheritance.

D. general inheritance.  

Right Answer is: C

SOLUTION

There are two types of relationship does exist between two classes - IS-A  and  HAS-A  relationship 


Q. 190257 A class “computer science” is derived from the class “employees”, which is again derived from the class “Extramarks”. This is an example of


A. multiple inheritance.

B. multilevel inheritance.

C. hierarchical inheritance.

D. single inheritance.

Right Answer is: B

SOLUTION

In multilevel inheritance, a derived class itself acts as a base class for another class.


Q. 190258 If the base class and a derived class include a member function of same name, the member function


A. of the derived class will be called by an object of the base class.

B. of the derived class will be called by an object of the derived class. 

C. of the base class will be called by an object of derived class.

D. of the base class will be called by an object of any class.

Right Answer is: B

SOLUTION

The member function of derived class is always accessed first in compare to base class.


Q. 190259 When a class contains objects of other class types as its member, it is referred to as


A. aggregation.

B. indirect base class.

C. general base class.

D. double base class.

Right Answer is: A

SOLUTION

Aggregation is the feature in which a class contains objects of other class types as its member. It is also known as containership or containment.


Q. 190260 A base class that does not appear directly in the declaration of derived class, but is available to the derived class through one of its base classes is called as


A. direct base class.

B. indirect base class.

C. general base class.

D. double base class.

Right Answer is: B

SOLUTION

For a given class, all base classes that are not direct base classes are indirect base classes.


Q. 190261 If we want the compiler to use dynamic binding for the specific function, then we declare the function with the keyword


A. virtual.

B. friend.

C. abstract.

D. public.

Right Answer is: A

SOLUTION

We can specify that the compiler match a function call with the correct function definition at run time; this is called dynamic binding.


Q. 190262 When a base class and a derived class have public member functions with the same name and parameter list types, then


A. the function in the derived class gets higher priority, when the function is called as a member of the derived class object.

B. the function in the base class gets higher priority, when the function is called as a member of the derived class object.

C. the function in the derived class gets higher priority, when the function is called as a member of the base class object.

D. the function in the base class gets higher priority always.

Right Answer is: A

SOLUTION

The derived class is one, which derives the properties of base classes.


Q. 190263 Among the following, the true statement is


A. Creating a derived class from a base class requires fundamental changes to the base class.  

B. In private inheritance, part of the base class interface can be made available to the functions outside the derived class.

C. The size of a derived class object is equal to the size of data members in the derived class only.

D. It is illegal to make objects of one class as members of another class.  

Right Answer is: B

SOLUTION

When we inherit privately, all public members of the base class become private for the derived class. If we want only some of them to remain private and the rest to be accessible from outside the derived class, it can also be done.


Q. 190264 To make a private member of the base class inheritable, declare it under


A. public section of the base class.

B. private section of the base class.

C. protected section of the base class.

D. access modifier section of the base class.

Right Answer is: C

SOLUTION

To make private members of the base class inheritable, declare it under protected section of the base class.


Q. 190265 Deriving a class from more than one base class is called


A. single inheritance.

B. multiple inheritance.

C. multilevel inheritance.

D. hierarchical inheritance.

Right Answer is: B

SOLUTION

We can derive a class from any number of base classes in multiple inheritance. Here one derived class can inherit the properties from more than one base classes.


Q. 190266 All of the following statements is true except:


A. Inheritance and friendship are very similar

B. Virtual base classes remove ambiguity in inheritance

C. A nested class object can be declared within the outer class

D. In containership, only the object of another class is declared in a class

Right Answer is: A

SOLUTION

In C++, friendship is not inherited. If a base class has a friend function, then the function doesn't become a friend of the derived class(es).


Q. 190267 Give the output of
class a{
class b{ public: b(){cout<<" the pussycat ";} }; public: a(){cout<<" the owl ";} b ob; }; void main(){ a oa; }


A. the owl the pussycat

B. the pussycat the owl

C. the owl

D. the pussycat

Right Answer is: B

SOLUTION

Object of a contains object of b so, constructor of b is called before constructor of a.


Q. 190268 Give the output of                                
           class a{
                  public:        a(){cout<<" the owl ";}        class b{             public:                 b(){cout<<" the pussycat ";}             }; }; void main(){    a oa;    a::b ob; }  


A. the owl the pussycat

B. the owl

C. the pussycat the owl

D. error

Right Answer is: A

SOLUTION

At first constructor of a will be executed. After it the statement a::b ob will execute constructor of class b.


Q. 190269 Give the output of
class a{
public: a(){cout<<"the sun is shining ";} }; class b{ a oa; public: b(){cout<<"make hay while ";} }; class c{ b ob; public: c(){cout<<"its bright";} }; void main(){ c oc; }


A. make hay while the sun is shining bright

B. its bright make hay while the sun is shining

C. the sun is shining make hay while its bright

D. its bright while the sun is shining

Right Answer is: C

SOLUTION

When an object of an derived class(c) is created, the program first calls the constructor for base class, then the constructor for the derived class.


Q. 190270 Give the output of   
           class a{ int x;     public:        a(){cout<<"the sun is shining ";                x=0;        } }; class b{        int y;        a oa;     public:        b(){cout<<"make hay while ";} }; void main(){    b ob; }


A. make hay while the sun is shining

B. the sun is shining make hay while

C. make hay while

D. the sun is shining

Right Answer is: B

SOLUTION

When an object of a derived class is created, the program first calls the constructor for base class, then the constructor for the derived class.


Q. 190271 Give the output of                                                        
            class a{ int x;
                    public:        a(){cout<<"it is raining ";                x=0;        } }; class b: public a{        int y;     public:        b(){cout<<"cats and dogs";} };   void main(){    b ob; }


A. cats and dogs it is raining

B. it is raining

C. it is raining cats and dogs

D. cats and dogs

Right Answer is: C

SOLUTION

When an object of a derived class is created, the program first calls the constructor for base class, then constructor for the derived class.


Q. 190272 How are the below two statements are different -             
i)  class X : protected Y
ii)  class Z : Y


A. in i) X inherits Y in protected mode, ii) will give error

B. in i) X inherits Y in protected mode, ii) Z inherits Y in protected mode

C. in i) X inherits Y in protected mode, ii) Z inherits Y in private mode

D. in i) X inherits Y in protected mode, ii) Z inherits Y in public mode

Right Answer is: C

SOLUTION

The default access mode in C++ is private. Here in the statement - class Z : Y  // Z is privately derived from Y.


Q. 190273 Look at the code below -                                                
           class base{
                        int a;                  public:                         void getd();                         void disp(); }; class subc : base{             public:                int b; };
       Access level for getd() in class subc is                          


A. public

B. protected

C. private

D. personal

Right Answer is: C

SOLUTION

Default visibility mode is private. Inheritable members of base become private members of subc.


Q. 190274 What will be the output of -                                 
           class B1{
                       public:        void display(){cout<<"in B1";} }; class B2{              public:        void display(){cout<<"in B2";} }; class D : public B1, public B2{       public:             void display(){ cout<<"in D";  }   };   void main(){    D od;    od.display(); }  


A. error

B. in D 

C. in B1 in B2 in D

D. in D in B2 in B1

Right Answer is: B

SOLUTION

The object calls its own class member named display( ).


Q. 190275 What will be the output of the given code-             
           class B1{     public:        void display(){cout<<"in B1";} }; class B2{              public:        void display(){cout<<"in B2";} }; class D : public B1, public B2{             void getdat();    }; void main(){    D od;    od.display();             }         


A. in B1

B. in B2

C. in B1 in B2

D. error

Right Answer is: D

SOLUTION

Class D inherits two functions of the same name ,i.e., display(). Calling the function with class name is used to avoid ambiguity.


Q. 190276 Define constructor for class B which has no data members  -            
          class A{
                       int len;                        int wid;                public:                     A( int a, int b){                               len=a;                               wid=b;             }                     void getd();                     void dispd(); }; class B : public A{                     public:                     };  


A. B( ) {}

B. B( int x, int y, int z) : A(int x, int y){}

C. B( int x, int y, int z) : A(x,y){}

D. B( int a, int b) : A(a, b){}

Right Answer is: D

SOLUTION

Constructors and destructors of base class are not inherited by the derived class. Rather, whenever, the derived class nedds to invoke base class's constructor or destructor, it can invoke them through explicitly calling them.


Q. 190277 class Dog is privately derived from class Animal.  An object of class Dog in main() can access


A. public members of class Animal

B. protected members of class Animal

C. public members of class Dog

D. private members of class Dog

Right Answer is: C

SOLUTION

With privately derived class, the public and protected members of the base class become private members of the derived class.


Q. 190278 The output of the following code will be: class Base1 {
public:
Base1()
{ cout << " Base1's constructor called" << endl; }};
class Base2 {
public:
Base2()
{ cout << "Base2's constructor called" << endl; }};
class Derived: public Base1, public Base2 {
public:
Derived()
{ cout << "Derived's constructor called" << endl; }
};
int main()
{
Derived d;
return 0;
}


A. Base1′s constructor called
Base2′s constructor called
Derived’s constructor called

B. Compiler dependent

C. Base2′s constructor called
Base1′s constructor called
Derived’s constructor called

D. Compiler error

Right Answer is: A

SOLUTION

When a class inherits from multiple classes, constructors of base classes are called in the same order as they are specified in the inheritance. 
Output:


Q. 190279 The ambiguity in multiple inheritance can be resolved through:


A. Derived class

B. Abstract class

C. Virtual base class

D. Base class

Right Answer is: C

SOLUTION

When two or more objects are derived from a common base class, we can prevent multiple copies of the base class being present in an object derived from those objects by declaring the base class as virtual when it is being inherited. Such a base class is known as virtual base class. 


Q. 190280 Given the definitions below,  answer the question that follows.              
           class Ani{ 
                    int num;     protected :       char name[20];     public:        void getANi();        void  calc();        int loc; }; class Bir {                float kg;          protected :              float speed;          public:            void getBir();            int dispBir(); }; class Cru : public Bir, public Ani{        int cr[10];        char getcru();        void dispcru();  }; How many bytes are taken up by objects of class Ani, Bir and Cru respectively?  


A. 20, 4, 0

B. 22,4,10

C. 24,8, 40

D. 24, 8, 52

Right Answer is: D

SOLUTION

An int variable occupied 2 bytes whereas a float occupied 1 bytes. 


Q. 190281 Given the definition of following two classes, the constructor definition for class Alpha would be:
class Alpha{
int a;
float b;
char c;
public:
........... //constructor definition has to come here
}; class Beta : public Alpha {
public:
...........//constructor definition has to come here
};


A. Alpha (int i, float j, char k)
{ a=i; b = j; c=k;}

B. Alpha (i, j, k)
{ a=i; b = j; c=k;}

C. Alpha {int i, float j, char k}
( a=i; b = j; c=k;)

D. Alpha {int i, float j, char k}
( a=i, b = j, c=k)

Right Answer is: A

SOLUTION

class Alpha{
int a;
float b;
char c;
public:
Alpha (int i, float j, char k)
{ a=i; b = j; c=k;}
}; class Beta : public Alpha {
public:
Beta (int p, float q, char r) : Alpha (p,q,r)
{cout << "Beta constructor...";}
};


Q. 190282 Consider the following snippet code. The class constructor which can be called first at the time of declaration of an object of class Outlet would be:
class MNC
{ char Cname[25];
//Company name
protected:
char Hoffice[25]; //Head office
public:
MNC( );
char Country[25];
void EnterData( );
void DisplayData( );
};
class Branch:public MNC
{ long NOE; //Number of Employees
char Ctry[25]; //Country
protected:
void Association( );
public:
Branch( );
void Add( );
void Show( );
};
class Outlet:public Branch
{
char State[25];
public:
Outlet( );
void Enter( );
void Output( );
};


A. Outlet

B. Branch

C. Association

D. MNC

Right Answer is: D

SOLUTION

MNC class constructor can be called first at the time of declaration of an object of class Outlet. (When an object of the derived class is declared, in order to create it, firstly the constructor of the base class is invoked and then the constructor of the derived class is invoked. On the other hand, when an object of the derived class is destroyed, first the destructor of the derived class is invoked followed by the destructor of the base class.)


Q. 190283 Consider the following snippet code and name the member function(s) which are accessed from the object(s) of class Outlet: class MNC
{ char Cname[25];
//Company name
protected:
char Hoffice[25]; //Head office
public:
MNC( );
char Country[25];
void EnterData( );
void DisplayData( );
};
class Branch:public MNC
{ long NOE; //Number of Employees
char Ctry[25]; //Country
protected:
void Association( );
public:
Branch( );
void Add( );
void Show( );
};
class Outlet:public Branch
{
char State[25];
public:
Outlet( );
void Enter( );
void Output( );
};


A. Enter(), Add() and DisplayData

B. Enter(), Output(), Add(), Show(), EnterData() and DisplayData

C. Output(), Show(), EnterData() and DisplayData

D. EnterData() and DisplayData

Right Answer is: B

SOLUTION

Outlet::Enter( ) Outlet::Output( ) MNC::EnterData( ) MNC::DisplayData( ) Branch::Add( ) Branch::Show( )


Q. 190284 Consider the following code fragment. The number of bytes which will be required by an object of the class ElectronicDolls would be: class Dolls
{ char Dcode[5];
protected:
float Price;
void CalcPrice(float);
public:
Dolls();
void DInput();
void DShow();
};
class SoftDolls:public Dolls
{ char SDName[20];
float Weight;
public:
SoftDolls();
void SDInput();
void DShow();
};
class ElectronicDolls:public Dolls
{ char EDName[20];
char BatteryType[10];
int Batteries;
public:
ElecronicDolls();
void EDInput();
void EDShow();
};


A. 41

B. 42

C. 31

D. 56

Right Answer is: A

SOLUTION

41 bytes
The memory will be reserved as follows:
char Dcode[5]; //5 Bytes
float Price; //4 Bytes
char EDName[20]; //20 Bytes
char BatteryType[10]; //10 Bytes
int Batteries; //2 Bytes Total = 41 Bytes
 


Q. 190285 Consider the following code fragment. The type of inheritance which is used in the code: class Dolls
{ char Dcode[5];
protected:
float Price;
void CalcPrice(float);
public:
Dolls();
void DInput();
void DShow();
};
class SoftDolls:public Dolls
{ char SDName[20];
float Weight;
public:
SoftDolls();
void SDInput();
void DShow();
};
class ElectronicDolls:public Dolls
{ char EDName[20];
char BatteryType[10];
int Batteries;
public:
ElecronicDolls();
void EDInput();
void EDShow();
};


A. Hybrid inheritance

B. Multiple inheritance

C. Hierarchical inheritance

D. Multilevel inheritance

Right Answer is: C

SOLUTION

In the given code, hierarchical inheritance has been used because the subclasses are derived from a single base class, which is Dolls.


Q. 190286 Look at the class definitions below -                                  
             class A{ 
            …… }; class B:public A{             …… }; class C : public B{             ……. };   C oc; In what order will constructors and destructors be invoked?  


A. A::A(), B::B(), C::C(), A::~A(),  B::~B(), C::~C()

B. C::C(), B::B(), A::A(), C::~C(),  B::~B(), A::~A()

C. C::C(), B::B(), A::A(), A::~A(),  B::~B(), C::~C()

D. A::A(), B::B(), C::C(), C::~C(),  B::~B(), A::~A()

Right Answer is: D

SOLUTION

When an object of a derived class is created, the program first calls the constructor for base class, then the constructor for the derived class. Similarly, when an object expires, the program calls the derived destructor, if any, and then the base destructor.


Q. 190287 A Nested class 


A. is an example of inheritance

B. cannot have objects outside

C. is a class defined within another class

D. can be declared only under private 

Right Answer is: C

SOLUTION

One class may have another class defined within it known as nested class.


Q. 190288 Which of the following statements is true?


A. No objects are declared for the abstract class

B. The derived class constructor initializes its own, and base class data members

C. Nested class members can be called by the objects of the containing class

D. The derived class can use only some of the inherited members like its own members

Right Answer is: A

SOLUTION

Object cannot be created for abstract class. It is just the blueprint of the superclass.


Q. 190289 Consider the following code fragment. The member functions accessible from an object of the class ElectronicDolls are: class Dolls
{ char Dcode[5];
protected:
float Price;
void CalcPrice(float);
public:
Dolls();
void DInput();
void DShow();
};
class SoftDolls:public Dolls
{ char SDName[20];
float Weight;
public:
SoftDolls();
void SDInput();
void DShow();
};
class ElectronicDolls:public Dolls
{ char EDName[20];
char BatteryType[10];
int Batteries;
public:
ElecronicDolls();
void EDInput();
void EDShow();
};


A. CalcPrice and DInput

B. EDInput( ), EDShow( ), DInput( ) and DShow( )

C. SDInput( ), SDShow( ), DInput( ) and DShow( )

D. EDInput( ), EDShow( )

Right Answer is: B

SOLUTION

ElectronicDolls::EDInput( ), ElectronicDolls::EDShow( ), Dolls::DInput( ), Dolls::DShow( )


Q. 190290 Reusability of classes can be implemented through:


A. Polymorphism

B. Abstract classes

C. Overloading

D. Inheritance

Right Answer is: D

SOLUTION

Reusability of classes can be implemented through inheritance. Reusability means adding additional features to an existing class without modifying it. This is achieved by deriving a new class from the existing one. The new class will have combined features of both the classes.


Q. 190291 When a derived class object is created,


A. first the derived class constructor is called then the base class constructor

B. first the base class constructor is called then the derived class constructor

C. only the base class constructor is called as it  is not inherited

D. the copy constructor is called to create it

Right Answer is: B

SOLUTION

When an object of a derived class is created, the program first calls the constructor for base class, then the constructor for the derived class.


Q. 190292 Visibility mode should be protected when


A. member are to be inaccessible from outside

B. member are to be inheritable but inaccessible from outside

C. member are to be inherited further

D. members are not to be inherited

Right Answer is: B

SOLUTION

With protected derived class, the public and protected members of the base class become protected members of the derived class. Thatmeans the inherited members are now not available to the outside world and can be accessed only through the member functions of the derived class and the classes based upon the derived class.


Q. 190293 If visibility mode is protected,


A. private, public and protected members become protected in the derived class

B. private, public and protected members become private, public and protected respectively in the derived class

C. public and protected members become protected in the derived class

D. public and protected members become public and protected respectively in the derived class

Right Answer is: C

SOLUTION

The protected derivation means that the derived class can access the public and private members of the base class protectedly.


Q. 190294 The inheritance that allows derived class to combine the strength of all the base classes is


A. multiple inheritance.

B. multilevel inheritance.

C. hierarchical inheritance.

D. single inheritance.

Right Answer is: A

SOLUTION

Multiple inheritance is when a subclass inherits from multiple base classes.


Q. 190295 The logical abstract base class for a class named “footballPlayer “ is


A. salary.

B. sport.

C. athlete.

D. team.

Right Answer is: C

SOLUTION

An abstract class is a class, which cannot be instantiated. It does not have instances.


Q. 190296 Abstract class cannot have


A. two instances.

B. any instance.

C. multiple instance.

D. zero and multiple instance.

Right Answer is: B

SOLUTION

An abstract class is a class, which cannot be instantiated. It has no instances. Abstract classes are the classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation.


Q. 190297 When an object is destroyed , the function which automatically gets called is


A. destructor.

B. constructor.

C. malloc().

D. calloc().

Right Answer is: A

SOLUTION

The destructors are used to deallocate memory, that was allocated for the object by the constructor.


Q. 190298 If we declare a class without any data member, then the size of that class


A. is 0 byte.

B. is 1 byte.

C. is 2 byte.

D. can not be determined.

Right Answer is: B

SOLUTION

An empty class has size 1 byte. It cannot have 0 byte size.


Q. 190299 Constructors and destructors of a base class


A. are same as that of that derived class.

B. cannot be inherited by derived class.

C. can be inherited by derived class.

D. cannot be invoked by derived class by explicitly calling them.

Right Answer is: B

SOLUTION

Derived classes cannot inherit but, invoke the constructor or destructor of a base class by explicitly calling them.


Q. 190300 When an object of a derived class expires, the sequence in which the destructor is invoked is


A. derived class destructor followed by base class destructor.

B. base class destructor followed by derived class destructor .

C. only base class destructor.

D. only derived class destructor .

Right Answer is: A

SOLUTION

It is analogous in the same way, as while destroying a building, firstly, the second floor is destroyed and then the first floor.


PreviousNext