Classes & Objects MCQ

1
A function abc is defined as
void abc (int   x =0, int y, int z=0)
{
       cout  <<  x  << y   << z ;
}
which of the following function calls is/are illegal? (Assume h , g  are declared as integers)
Option 1                      abc ( ) ;
Option 2                        abc (h) ;
Option 3                        All of these       [ ANS ]
Option 4                        None of the these
2
int    a=1,   b=2;
            a=chg(b);
            cout <<a<<b;
            If the function chg is coded as
int chg (int   x)
{
   x=10;
   retrun(11);
}
Then
Option 1                        It results in compile-time error   
Option 2                        It results in run time error
Option 3                        It prints 112       [ ANS ]
Option 4            I           t prints 1110
3
int    a=1,   b=2;
a=chg(b);
cout <<a<<b;
If the function chg is coded as
int chg (int    &x )
{
x  =10;
return(11);
}
Then
Option 1                        It results in compile-time error
Option 2                        It result in run time error
Option 3                        It prints 112
Option 4                        It prints 1110     [ ANS ]
4
int    a=1,   b=2;
a=chg(b);
cout <<a<<b;
If the function chg is coded as

int  chg(const int &x)

{

    x=10;

    return (11)

}

Then

Option 1                        It results in compile-time error    [ ANS ]

Option 2                        It result in run time error

Option 3                        It prints 112

Option 4                        It prints 1110

5
 

Consider the follwing program segment:

const char *p1=”To make the bitter butter Q No.1 of 10

 

The following C++ code results in

#include “iostream.h’’

void main (void)

{

      cout << (int  i=5) <<(int j= 6);

}

 

Option 1                        Compilation error           [ ANS ]

Option 2                        Run time error  

Option 3                        Link time error

Option 4                        None of the above

6
The statements

int a  =5;     

cout << “FIRST’’ << ( a<< 2 ) << “SECOND”;  

outputs

 

Option 1                        FIRST52 SECOND

Option 2                        FIRST20 SECOND       [ ANS ]

Option 3                        SECOND 25 FIRST

Option 4                        An error message

7
The following program fragment

void main (  )

{

int   x = 10;

int &p = x ;

cout   << &P   << & x;

}

 

Option 1                        Prints 10 and the address of  x

Option 2                        Result in a run time error

Option 3                        Prints the address of x and address of p twice                 [ ANS ]

Option 4                        None of these

8
The declaration

int   x ;

int &p=x ;

Is same as the declaration

int     x, *p ;     p =&x;

This remark is

Option 1                        True

Option 2                        False    [ ANS ]

Option 3                        Sometimes true

Option 4                        None of the above

9
The following program segment

const int     m= 10;

int & n = m;

n= 11;

cout <<  m  <<  n;

 

 

Option 1                        Result in compile time error        [ ANS ]

Option 2                        Result in run time error 

Option 3                        Prints   1111

Option 4                        Prints   1011

10
The following program segment

int   a =10;

int const   &b=a ;

a= 11;

cout<< a<<b;

 

Option 1                        Results in compile time error

Option 2                        Result in run time error

Option 3                        Prints   1111      [ ANS ]

Option 4                        None of the above

 

11
Consider the following program segment.

static char   X [3 ] = ’’1234”;

cout <<  x ;

A complete C++ program with these two statements

 

Option 1                        Prints 1234

Option 2                        Prints 123

Option 3                        Prints 1234 followed by some junk

Option 4                        Will give a compilation error       [ ANS ]

12
Consider the declarations

const char cc =’h’ ;

char *cp;

const char *const ccpc =&cc;

char *const cpcp;

Which of the following statements

 

Statements I:     cp =*cpcp;

 

Statements II:    **cpcp=*cp;

 

Statements III:    *cp = **cpcp;  are legal?

 

Option 1                        All are legal      [ ANS ]

Option 2                        All are illegal    

Option 3                        Only statement   I is illegal.

Option 4                        Statements I and III are illegal.

 

13
class A

{ public:

            A  (void)

                        {  cout  <<  “Howzhat”; }

            A (void)

            { cout << “whatizit” }

 

};

 

class B:A

{ public :

 

      B (void )

                 {  cout << “WYSIWYG";  }

       B  (void)

                cout  << “YACC”; }

};

 

The declaration B x;

Option 1                        Prints Howzhat WYSIWYG YACC  Whatizit     [ ANS ]

Option 2                        prints nothing

Option 3                        Prints YACC Whatizit Howzhat WYSIWYG

Option 4                        None of the above

14
class A

{ public:

            A  (void)

                        {  cout  <<  “Howzhat”; }

            A (void)

                        { cout << “whatizit” }

};

class B:A

{ public :

      B (void )

                 {  cout << “WYSIWYG";  }

            B  (void)

                 cout  << “YACC”; }

};

 

If the main function has the two statements

B  x;

cout<<"done";

 

Option 1                        Howzhat WYSIWYG  YACC Whatizit done.

Option 2                        Howzhat WYSIWYG done YACC Whatizit.      [ ANS ]

Option 3                        YACC Whatizit Howzhat WYSIWYG done

Option 4                        None of the these.

15
better“;  // stm1

char *const p2= “ Recommend this book 2 others“;  // stm2

p1= “add some better butter not bitter“;   //stm3

p2="so that they 2 will get benefited.";  //stm4

*(p1+3)=’A’   ;  //stm5

*(p2+3)=’A’;    // stm6

Which of the statement results in error?

 

Option 1                        Stm4  and stm5 [ ANS ]                       

Option 2                        Stm1   and stm2

Option 3                        Stm1   and stm4

Option 4                        Stm2   and stm3

 

16
The following program

void abc (int    &p)

{

            cout    << p;

 }

void main (void )

{

float m =   1.23;

abc (m);

cout    << m ;

}

 

Option 1                        Result in compilation error          [ ANS ]

Option 2                        Results in run time error

Option 3                        Prints 1.23

Option 4                        Prints 1

 

17
choose the best answer:

A function that does the same operation on different data types is to be implemented using

 

Option 1                        Macros

Option 2                        Overloading

Option 3                        Function templates         [ ANS ]

Option 4                        Default arguments

18
What is the output of the following C++program?

void abc( int x=0, int y=0)

{

  cout <<“Hi There“;

}

void abc(int x)

{

  cout <<”How R U doing today?":

 

}

 

void main (void)

{

 int m=5;

abc(m);

}

 

Option 1                        Hi there

Option 2                        How R U doing today?

Option 3                        Wat gets printed depends on how the particular compiler is implemented

Option 4                        It results in compilation error      [ ANS ]

 

19
Consider the declarations

char  a;

const char aa=‘h’;

char *na;

const char *naa;

Which of the following statements is/are illegal?

Statement I:   aa = a;

Statement II:  na=  &a;

Statement III:  na=&aa;

Option 1                        Only    I   and      II

Option 2                        Only    II   and     III

Option 3                        Only   I   and     III        [ ANS ]

Option 4                        All the three statements are illegal

 

20
#include ‘’iostream.h’’

int a(int m)

{ return ++m; }

 

int   b(int &m)

{ return   ++m; }

 

int c(char &m)

{ return ++m; }

 

void main(  )

{

  int   p=0, q=0 , r=0;

  p+=a (b(p));

  q+ =b(a (q));

  r+=a (c(r));

  cout <<p<<q<<r;

}

 

The above program prints:

 

Option 1                        Results in compilation error

Option 2                        Prints 123

Option 3                        Prints 111

Option 4                        Prints 322         [ ANS ]

21
#include iostream.h

 

int a(int m)

 

{ return ++m; }

 

int   b(int &m)

 

{ return   ++m; }

 

int c(char &m)

 

{ return ++m; }

 

void main(  )

{

 int   p=0, q=0 , r=0;

 p+=a (b(p));

 q+ =b(a (q));

 r+=a (c(r));

 cout <<p<<q<<r;

}

If the statement:

q+=b(a(q)): is replaced by the statement

q+=b(a(p)); then the above program:

 

Option 1                        Prints 111

Option 2                        Results in compilation error

Option 3                        Prints 322

Option 4                        Prints 352         [ ANS ]

 

22
the following program

class abc ;

class def

{

   int  i1;      // statement   1

   protected: int i2;    // statement  2

  public : int i3;    // statement  3

  friend abc;

} ;

class abc

{

public:

            void main (def A)

            {

                        cout<<( A.i1=3) ;

                        cout<<( A.i2=4);

                        cout<<( A.i3=5);

            }

void main ( )

{

 

  def x1;

 abc   x2;

 x2.mn(x1) ;

}

Option 1                        Will compile successuflly if statement 1 is removed

Option 2                        Will compile successfully if statement 2 is removed

Option 3                        Will compile successfully if statement 3 is removed

Option 4                        Will run successfully and print 345                      [ ANS ]

 

23
class mho

{ public:

             mho(void)

            {

                         cout<< ;

            }

            mho(mho  &x }

            {

                        cout<< ;

            }

 

             mho operator - ( mho y)

            {

                         mho ohm;

                         return (ohm) ;

            }

 

};

 

 If the function main is coded as

 mho   a, b;

 the output will be

Option 1                        there was there was      [ ANS ]

Option 2                        nothing

Option 3                        a run time error

Option 4                        there was a certain man there was a certain man

 

24
The following C++ code results in

#include “iostream.h’’

void main (void)

{

      cout << (int  i=5) <<(int j= 6);

}

 

Option 1                        Compilation error           [ ANS ]

Option 2                        Run time error  

Option 3                        Link time error

Option 4                        None of the above

 

25
The statements

int a  =5;     

cout << “FIRST’’ << ( a<< 2 ) << “SECOND”;  

outputs

 

Option 1                        FIRST52 SECOND

Option 2                        FIRST20 SECOND       [ ANS ]

Option 3                        SECOND 25 FIRST

Option 4                        An error message

26
The following program fragment

void main (  )

{

int   x = 10;

int &p = x ;

cout   << &P   << & x;

}

 

Option 1                        Prints 10 and the address of  x

Option 2                        Result in a run time error

Option 3                        Prints the address of x and address of p twice                 [ ANS ]

Option 4                        None of these

27
The declaration

int   x ;

int &p=x ;

Is same as the declaration

int     x, *p ;     p =&x;

This remark is

Option 1                        True

Option 2                        False    [ ANS ]

Option 3                        Sometimes true

Option 4                        None of the above

28
The following program segment

const int     m= 10;

int & n = m;

n= 11;

cout <<  m  <<  n;

 

 

Option 1                        Result in compile time error        [ ANS ]

Option 2                        Result in run time error 

Option 3                        Prints   1111

Option 4                        Prints   1011

29
The following program segment

int   a =10;

int const   &b=a ;

a= 11;

cout<< a<<b;

 

Option 1                        Results in compile time error

Option 2                        Result in run time error

Option 3                        Prints   1111      [ ANS ]

Option 4                        None of the above

30
Consider the following program segment.

static char   X [3 ] = ’’1234”;

cout <<  x ;

A complete C++ program with these two statements

 

Option 1                        Prints 1234

Option 2                        Prints 123

Option 3                        Prints 1234 followed by some junk

Option 4                        Will give a compilation error       [ ANS ]

31
Consider the declarations

const char cc =’h’ ;

char *cp;

const char *const ccpc =&cc;

char *const cpcp;

Which of the following statements

 

Statements I:     cp =*cpcp;

 

Statements II:    **cpcp=*cp;

 

Statements III:    *cp = **cpcp;  are legal?

 

Option 1                        All are legal      [ ANS ]

Option 2                        All are illegal    

Option 3                        Only statement   I is illegal.

Option 4                        Statements I and III are illegal.

32
class A

{ public:

            A  (void)

                        {  cout  <<  “Howzhat”; }

            A (void)

            { cout << “whatizit” }

 

};

 

class B:A

 

{ public :

 

      B (void )

                 {  cout << “WYSIWYG";  }

       B  (void)

                cout  << “YACC”; }

};

 

The declaration B x;

 

Option 1                        Prints Howzhat WYSIWYG YACC  Whatizit     [ ANS ]

Option 2                        prints nothing

Option 3                        Prints YACC Whatizit Howzhat WYSIWYG

Option 4                        None of the above

33
class A

{ public:

            A  (void)

                        {  cout  <<  “Howzhat”; }

            A (void)

                        { cout << “whatizit” }

};

class B:A

{ public :

      B (void )

                 {  cout << “WYSIWYG";  }

            B  (void)

                 cout  << “YACC”; }

};

 

If the main function has the two statements

B  x;

cout<<"done";

 

Option 1                        Howzhat WYSIWYG  YACC Whatizit done.

Option 2                        Howzhat WYSIWYG done YACC Whatizit.      [ ANS ]

Option 3                        YACC Whatizit Howzhat WYSIWYG done

Option 4                        None of the these.

 

 

34
Which of the follwing comments about inline comments are true?

Option 1                        A function is declared inline by typing the keyword inline before the return value of the function.                             [ ANS ]

Option 2                        A function is declared inline by typing the keyword inline after the return value of the function

Option 3                        Inline functions are essentially same as implementing a function as macro.

Option 4                        None of these

 

Q No.2 of 10

Which of the following decides if a function that is declared inline is indeed going to be treated inline in the executable code?

Option 1                        Compiler           [ ANS ]

Option 2                        linker

Option 3                        Loader

Option 4                        preprocessor

35
Which of the following type of functions is an ideal candidate for being declared inline?

Option 1                        A function that is small and is not called frequently

Option 2                        A function that is small and is called frequently.   [ ANS ]                       

Option 3                        A function that is not small and is not called frequently

Option 4                        A function that is not small and is called frequently.

36
One of the disadvantages of pass-by reference is that the called function may inadvertently corrupt the caller’s data. This can be avoided by

 

Option 1                        Passing pointers

Option 2                        Declaring the formal parameters consant            [ ANS ]           

Option 3                        Declaring the actual parameters constant

Option 4                        All of the above

37
At what point of time a variable comes into existence in memory is determined by its

Option 1                        Scope

Option 2                        Storage class     [ ANS ]

Option 3                        Data type         

Option 4                        All of the above

38
Which of the following specifiers need not be honored by the compiler?

Option 1                        Register & inline                       [ ANS ]

Option 2                        Static

Option 3                        Extern

Option 4                        None of these

39
Which of the following cannot be declared static?

Option 1                        Class and Object           [ ANS ]           

Option 2                        Functions

Option 3                        Member variables

Option 4                        All of these

40
The order is which operands are evaluated in an expression is predictable if the operator is

Option 1                        *

Option 2                        +

Option 3                        %

Option 4                        &&      [ ANS ]

 

41
The following program fragment

int  i =10;

void main ( )

   {

   int  i=20;

   {

      int  i=30;

      cout << i<< : : i ;

   }

}

Option 1                        Prints 3010        [ ANS ]

Option 2                        Print 3020

Option 3                        Will result in a run time error

Option 4                        None of the above

42
A  function abc is defined as

void abc   (int  x=0 , int  y=0)

{

            cout   <<  x  <<   y;

 }

Which of the following function calls is /are illegal? (Assume h, g are declared as integers)

Option 1                        abc (  ) ;

Option 2                        abc  (h);

Option 3                        abc (h,h);

Option 4                        None of these   [ ANS ]

43
cout stand for   

Option 1                        Class output

Option 2                        Character output

Option 3                        Common output [ ANS ]           

Option 4                        Call output

44
Reference is not same as pointer because

Option 1                        a reference can never be null

Option 2                        a reference once established cannot be changed.

Option 3                        reference does not need an explicit dereferencing mechanism

Option 4                        All of these                   [ ANS ]

45
It a piece of code can be implemented as a macro or as an inline function. Which of the following factors favour implementation as an inline function?

Option 1                        Flexibility to manipulate as a pointer

Option 2                        Interacting with other components (like variables in an expression) in the correct way.

Option 3                        None of these

Option 4                        All of these                   [ ANS ]

46
The fields in a structure of a C program are by default

Option 1                        protected

Option 2                        public    [ ANS ]

Option 3                        private

Option 4                        none of the above

47
the fields in a class, of a C++ program are by default

Option 1                        protected

Option 2                        public

Option 3                        private  [ ANS ]                       

Option 4                        none of the above

48
class A

{          int i1;

protected:

            int i2;

public:

            int i3;

};

class B : public A

{ public:

            int i4;

};

class C : B

{ };

the variable i2 is accessible

Option 1                        to a public function in class A

Option 2                        to public function in class B

Option 3                        to a public function in class C

Option 4                        all of these        [ ANS ]

49
class A

{ int i1;

protected:

            int i2;

public:

            int i3;

};

class B : public A

{ public:

            int i4;

};

class C : B

{ };

which variable (s) is/are accessible from the main function?

Option 1                        i1

Option 2                        i2

Option 3                        i3

Option 4                        None of the above                     [ ANS ]

50
Forgetting to include a file ( like cmath or math.h) that is necessary will result in

Option 1                        Compilation error

Option 2                        Warning when the program is run

Option 3                        Error at link time                       [ ANS ]

Option 4                        Warning when the program is compiled

51
Class Dog : public X, public Y

is an example of

Option 1                        Multiple inheritance       [ ANS ]

Option 2                        Repeated inheritance

Option 3                        Linear inheritance

Option 4                        None of the above

52
Choose the correct statements.

Option 1                        A destructor is not inherited

Option 2                        A constructor cannot be called explicitly

Option 3                        A constructor is not inherited

Option 4                        All of these       [ ANS ]

53
The compiler identifies a virtual function to be pure

Option 1                        by the presence of the keyword pure

Option 2                        by its location in the program

Option 3                        if it is equated to 0         [ ANS ]

Option 4                        none of the above

54
Let class APE be a friend of class SAPIEN. Let class HUMAN be a child class of SAPIEN and let MONKEY be a child class of APE. Then

Option 1                        SAPIEN is not a friend of APE

Option 2                        APE is not a friend of HUMAN

Option 3                        MONKEY is not afriend of SAPIEN

Option 4                        All of these       [ ANS ]

55
A class having no name

Option 1                        cannot have a constructor

Option 2                        cannot have a destructor

Option 3                        cannot be passed as an argument

Option 4                        all of these        [ ANS ]

 

56
For a method to be an interface between the outside world and a class, it had to be declard

Option 1                        private

Option 2                        protected

Option 3                        public    [ ANS ]

Option 4                        external

57
Choose the correct statement(s) from the following.

Option 1                        In a struct, the access control is public by default.            [ ANS ]

Option 2                        In a struct, the access control is private by default.

Option 3                        In a class, the access control is public by default.

Option 4                        None of these

58
Overloading is otherwise called as

Option 1                        Virtual polymorphism

Option 2                        Transient polymorphism

Option 3                        Pseudo polymorphism

Option 4                        Ad-hoc polymorphism    [ ANS ]

59
C++ encourages structuring a software as a collection of components that are

Option 1                        Highly cohesive and loosely coupled       [ ANS ]                       

Option 2                        Not highly cohesive but loosely coupled

Option 3                        Highly cohesive and tightly coupled

Option 4                        Not highly cohesive but tightly coupled

60
Which of the follwing parameter passing mechanism(s) is /are supported by C++, but not by C?

Option 1                        Pass by value

Option 2                        Pass by reference                     [ ANS ]                       

Option 3                        Pass by value-result

Option 4                        All of the above

61
C++ was originally developed by

Option 1                        Clocksin and Mellish

Option 2                        Donald E. Knuth

Option 3                        Sir Richard Hadlee

Option 4                        Bjarne Stroustrup                      [ ANS ]

62
cfront

Option 1                        Is the front end of a C compiler

Option 2                        Is the pre-processor of a C compiler

Option 3                        Is a tool that translates a C++ code to its equivalent C code[ ANS ]        

Option 4                        None of the above

63
Reusability is a desirable feature of a language as it

Option 1                        Decreases the testing time

Option 2                        Lowers the maintenance cost

Option 3                        All of these       [ ANS ]           

Option 4                        None of these

64
Choose the correct statements regarding inline function.

Option 1                        It speeds up execution

Option 2                        It increases the code size

Option 3                        All of these       [ ANS ]

Option 4                        None of these

65
If many function have the same name, which of the following information, if present, will be used by the compiler to invoke the correct function to be used?

Option 1                        The operator: :

Option 2                        Function signature

Option 3                        All of these       [ ANS ]

Option 4                        None of the above

 

66
Choose the correct remarks

Option 1                        Some of the existing operators cannot be overloaded.

Option 2                        Operator precedence cannot be changed.

Option 3                        None of these

Option 4                        All of the above.            [ ANS ]

67
A constructor is called whenever

Option 1                        An object is declared     [ ANS ]                       

Option 2                        An object is used

Option 3                        A class is declared

Option 4                        A class is used

68
Which of the following remarks about the differences between constructors and destructors are correct?

Option 1                        Constructors can take arguments but destructors cannot.[ ANS ]

Option 2                        Destructors can take arguments but constructors cannot.

Option 3                        Destructors can be overloaded but constructors cannot be overload.

Option 4                        None of these

69
Which of the following is not a storage class supported by C++?

Option 1                        register

Option 2                        auto

Option 3                        mutable

Option 4                        dynamic                        [ ANS ]

70
Which of the following operators cannot overloaded?

Option 1                        ?:

Option 2                        .

Option 3                        All of these       [ ANS ]           

Option 4                        No such operator exists