Programs

Question 11 :

Which of the following statement is correct about the program given below?

#include < iostream . h > 
class IndiaParinam
{
    int x; 
    public:
    IndiaParinam(short ss)
    {
        cout<< "Short" << endl;
    }
    IndiaParinam(int xx)
    {
        cout<< "Int" << endl;
    }
    IndiaParinam(char ch)
    {
        cout<< "Char" << endl;
    }
    ~IndiaParinam() 
    {
        cout<< "Final";
    }
};
int main()
{
    IndiaParinam *ptr = new IndiaParinam('B');
    return 0; 
}


A). The program will print the output Short .
B). The program will print the output Int .
C). The program will print the output Char .
D). The program will print the output Final .
E). None of the above
Answer : Option C

Question 12 :

Which of the following statement is correct about the program given below?

#include < iostream . h > 
class IndiaParinam
{
    int x; 
    public:
    IndiaParinam(short ss)
    {
        cout<< "Short" << endl;
    }
    IndiaParinam(int xx)
    {
        cout<< "Int" << endl;
    }
    IndiaParinam(float ff)
    {
        cout<< "Float" << endl;
    }
    ~IndiaParinam() 
    {
        cout<< "Final";
    }
};
int main()
{
    IndiaParinam *ptr = new IndiaParinam('B');
    return 0; 
}


A). The program will print the output Short .
B). The program will print the output Int .
C). The program will print the output Float .
D). The program will print the output Final .
E). None of the above
Answer : Option B

Question 13 :

What will be the output of the following program?

#include < iostream . h >
class ParinamBase
{   
    public:
    ParinamBase()
    {
        cout<< "Base OK. "; 
    }
    ~ParinamBase()
    {
        cout<< "Base DEL. "; 
    }
};
class ParinamDerived: public ParinamBase
{
    public:
    ParinamDerived()
    { 
        cout<< "Derived OK. "; 
    }
    ~ParinamDerived()
    { 
        cout<< "Derived DEL. "; 
    }
};
int main()
{
    ParinamBase *basePtr = new ParinamDerived();
    delete basePtr;
    return 0;
}


A). Base OK. Derived OK.
B). Base OK. Derived OK. Base DEL.
C). Base OK. Derived OK. Derived DEL.
D). Base OK. Derived OK. Derived DEL. Base DEL.
E). Base OK. Derived OK. Base DEL. Derived DEL.
Answer : Option B

Question 14 :

What will be the output of the following program?

#include < iostream . h >
class ParinamBase
{   
    public:
    ParinamBase()
    {
        cout<< "Base OK. "; 
    }
    virtual ~ParinamBase()
    {
        cout<< "Base DEL. "; 
    }
};
class ParinamDerived: public ParinamBase
{
    public:
    ParinamDerived()
    { 
        cout<< "Derived OK. "; 
    }
    ~ParinamDerived()
    { 
        cout<< "Derived DEL. "; 
    }
};
int main()
{
    ParinamBase *basePtr = new ParinamDerived();
    delete basePtr;
    return 0;
}


A). Base OK. Derived OK.
B). Base OK. Derived OK. Base DEL.
C). Base OK. Derived OK. Derived DEL.
D). Base OK. Derived OK. Derived DEL. Base DEL.
E). Base OK. Derived OK. Base DEL. Derived DEL.
Answer : Option D

Question 15 :

What will be the output of the following program?

#include < iostream . h > 
class ParinamBase
{
    public:
    int x, y;
    ParinamBase(int xx = 0, int yy = 5)
    {
        x = ++xx; 
        y = --yy;
    }
    void Display()
    {
        cout<< --y;
    } 
    ~ParinamBase(){} 
};
class ParinamDerived : public ParinamBase
{
    public:
    void Increment()
    {
        y++;
    }
    void Display()
    {
        cout<< --y;
    } 
}; 
int main()
{
    ParinamDerived objParinam;
    objParinam.Increment();
    objParinam.Display();
    return 0; 
}


A). 3
B). 4
C). 5
D). Garbage-value
E). The program will report compile time error.
Answer : Option B