OOPS in C++ MCQs Exercise II

Ques 1 OOPS


What is the output of the following C++ Code?


class A
{
public:
       A()
       {          
           cout<<"A Present";
       }
       ~A()
       {
	   cout<<"A Absent ";
       }
};
class B: public A
{
public:
       B()
       { 
              cout<<"B Present";
       }
       ~B()
       {     
              cout<<"B Absent ";
       }
};
int main()
{
      B obj;
      return 0; 
}

A B Present B Absent
B B Present B Absent A Present A Absent
C A Present B Present B Absent A Absent
D A Present B Present A Absent B Absent

Ques 2 OOPS


What is the output of the following C++ Code?


class SmallCode
{
    SmallCode()
   {
        cout << "SmallCode Constructor is Called";
    }
};
int main() 
{
   SmallCode s1;
   return 0;
}

A Compilation Error
B SmallCode Constructor is Called
C None
D None of these

Ques 3 OOPS


What is the output of the following C++ Code?


class SmallCode
{
    SmallCode()
   {
        cout << "SmallCode Constructor is Called";
    }
};
int main() 
{
   SmallCode obj1, *obj2;
   return 0;
}

A Compilation Error
B SmallCode Constructor is Called
C None
D None of these

Ques 4 OOPS


What is the output of the following C++ Code?


class SmallCode
{
    public:
        int num;
};
int main()
{
    SmallCode obj1= {100};
    SmallCode obj2=obj1;
    cout << obj1.num << " " << obj2.num;
    return 0;
}

A 100 0
B 100 100
C 100 followed by garbage value
D Compilation Error