Question 96

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class First
{
public:
First() { cout << "Constructor";}
void Print(){ cout<<"from First";}
};
int main()
{
First FirstObject;
FirstObject.Print();
}
  • Question 97

    Given:
    #include <iostream>
    #include <exception>
    using namespace std;
    int main () {
    try
    {
    int * myarray= new int[1000];
    }
    catch (bad_alloc&)
    {
    cout << "Error allocating memory";
    }
    catch (exception& e)
    {
    cout << "Standard exception";
    }
    catch (...)
    {
    cout << "Unknown exception";
    }
    return 0;
    }
    What will happen if we use the operator "new" and the memory cannot be allocated?
  • Question 98

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    class BaseC
    {
    int *ptr;
    public:
    BaseC() { ptr = new int(10);}
    BaseC(int i) { ptr = new int(i); }
    ~BaseC() { delete ptr; }
    void Print() { cout << *ptr; }
    };
    int main()
    {
    BaseC *o = new BaseC(5);
    o->Print();
    }
  • Question 99

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    class A {
    public:
    virtual void Print()=0;
    };
    class B:public A {
    public:
    virtual void Print() { cout<< "B"; }
    };
    class C:public A {
    public:
    virtual void Print() { cout<< "C"; }
    };
    int main()
    {
    B ob2;
    C ob3;
    A *obj;
    obj = &ob2;
    obj->Print();
    obj = &ob3;
    obj->Print();
    }
  • Question 100

    What happens when you attempt to compile and run the following code?
    #include <iostream> using namespace std;
    class A { public: int x; A() { x=0;} };
    class B : public A {
    public:
    B() { x=1;}
    };
    class C : private B {
    public:
    C() { x=2;}
    };
    int main () {
    C c1;
    cout << c1.x;
    return 0;
    }