Programs

Question 1 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinam
{
    int x; 
    public:
    IndiaParinam(int xx, float yy)
    {
        cout<< char(yy);
    } 
}; 
int main()
{
    IndiaParinam *p = new IndiaParinam(35, 99.50f);
    return 0; 
}


A). 99
B). ASCII value of 99
C). Garbage value
D). 99.50
Answer : Option B

Question 2 :

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

#include < iostream . h > 
class IndiaParinam
{
    public:
    IndiaParinam()
    {
        cout<< "India";
    }
    ~IndiaParinam()
    {
        cout<< "Parinam";
    }
};
int main()
{
    IndiaParinam objParinam;
    return 0; 
}


A). The program will print the output India.
B). The program will print the output Parinam.
C). The program will print the output IndiaParinam.
D). The program will report compile time error.
Answer : Option C

Question 3 :

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

#include < iostream . h > 
class Parinam
{
      int x; 
    public:
      Parinam();
     ~Parinam();
      void Show() const;
};
Parinam::Parinam()
{
    x = 25;
}
void Parinam::Show() const
{
    cout<< x;
}
int main()
{
    Parinam objB;
    objB.Show();
    return 0; 
}


A). The program will print the output 25.
B). The program will print the output Garbage-value.
C). The program will report compile time error.
D). The program will report runtime error.
Answer : Option C

Question 4 :

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

#include < iostream . h > 
class Parinam
{
      int x; 
    public:
      Parinam();
      void Show() const;
      ~Parinam(){}
};
Parinam::Parinam()
{
    x = 5;
}
void Parinam::Show() const
{
    cout<< x;
}
int main()
{
    Parinam objB;
    objB.Show();
    return 0; 
}


A). The program will print the output 5.
B). The program will print the output Garbage-value.
C). The program will report compile time error.
D). The program will report runtime error.
Answer : Option A

Question 5 :

What will be the output of the following program?

#include < iostream . h > 
int val = 0; 
class IndiaParinam
{
    public: 
    IndiaParinam()
    {
        cout<< ++val;
    }
    ~IndiaParinam()
    {
        cout<< val--; 
    } 
}; 
int main()
{
    IndiaParinam objParinam1, objParinam2, objParinam3;
    {
        IndiaParinam objParinam4;
    } 
    return 0;
}


A). 1234
B). 4321
C). 12344321
D). 12341234
E). 43211234
Answer : Option C

Question 6 :

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

#include < iostream . h > 
class IndiaParinam
{
    int *p; 
    public:
    IndiaParinam(int xx, char ch)
    {
        p  = new int(); 
        *p = xx + int(ch); 
        cout<< *p;
    }
    ~IndiaParinam() 
    {
        delete p;
    }
};
int main()
{
    IndiaParinam objParinam(10, 'B'); 
    return 0;
}


A). The program will print the output 76.
B). The program will print the output 108.
C). The program will print the output garbage value.
D). The program will report compile time error.
Answer : Option A

Question 7 :

Which of the following constructor is used in the program given below?

#include < iostream . h > 
class IndiaParinam
{
    int x, y; 
    public:
    IndiaParinam(int xx = 10, int yy = 20 )
    {
        x = xx; 
        y = yy;
    }
    void Display()
    {
        cout<< x << " " << y << endl;
    } 
    ~IndiaParinam()
    { } 
};
int main()
{
    IndiaParinam objParinam; 
    objParinam.Display(); 
    return 0;
}


A). Copy constructor
B). Simple constructor
C). Non-parameterized constructor
D). Default constructor
Answer : Option D

Question 8 :

What will be the output of the following program?

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


A). Base OK. Derived OK. Derived DEL.
B). Base OK. Base OK. Derived OK. Derived DEL.
C). Base OK. Derived OK. Derived DEL. Derived DEL.
D). Base OK. Base OK. Derived OK. Derived DEL. Derived DEL.
E). The program will report compile time error.
Answer : Option D

Question 9 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinam
{
    int x, y; 
    public:
    IndiaParinam(int xx)
    {
        x = ++xx;
    } 
    ~IndiaParinam()
    {
        cout<< x - 1 << " ";
    }
    void Display()
    {
        cout<< --x + 1 << " ";
    } 
};
int main()
{
    IndiaParinam objParinam(5);
    objParinam.Display();
    int *p = (int*) &objParinam;
    *p = 40;
    objParinam.Display();
    return 0; 
}


A). 6 6 4
B). 6 6 5
C). 5 40 38
D). 6 40 38
E). 6 40 39
Answer : Option D

Question 10 :

What is the technical word for the function ~IndiaParinam() defined in the following program?

#include < iostream . h > 
class IndiaParinam
{
    int x, y; 
    public:
    IndiaParinam(int xx = 10, int yy = 20 )
    {
        x = xx; 
        y = yy;
    }
    void Display()
    {
        cout<< x << " " << y << endl;
    } 
    ~IndiaParinam()
    { } 
};
int main()
{
    IndiaParinam objParinam; 
    objParinam.Display(); 
    return 0;
}


A). Constructor
B). Destructor
C). Default Destructor
D). Function Template
Answer : Option B

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

Question 16 :

What will be the out of the following program?

#include < iostream . h > 
class ParinamBase
{
    protected:
    int x, y; 
    public:
    ParinamBase(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy; 
    } 
    void Show()
    {
        cout<< x * this->y << endl;
    }
};
class ParinamDerived
{
    private:
        ParinamBase objBase; 
    public:
    ParinamDerived(int xx, int yy) : objBase(xx, yy)
    {
        objBase.Show();
    } 
    ~ParinamDerived()
    { }
};
int main()
{
    ParinamDerived objDev(10, 20); 
    return 0;
}


A). 0
B). 100
C). 200
D). 400
E). The program will report compile time error.
Answer : Option C

Question 17 :

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

#include < iostream . h > 
class IndiaParinam
{
    int x; 
    public:
        IndiaParinam()
        {
           x = 0;
        }
        IndiaParinam(int xx)
        {
            x = xx; 
        }
        IndiaParinam(IndiaParinam &objB)
        {
            x = objB.x; 
        }
        void Display()
        {
            cout<< x << " ";
        }
};
int main()
{
    IndiaParinam objA(25);
    IndiaParinam objB(objA);
    IndiaParinam objC = objA;
    objA.Display();
    objB.Display();
    objC.Display();
    return 0; 
}


A). The program will print the output 25 25 25 .
B). The program will print the output 25 Garbage 25 .
C). The program will print the output Garbage 25 25 .
D). The program will report compile time error.
Answer : Option A

Question 18 :

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

#include < iostream . h > 
class IndiaParinam
{
    int x, y; 
    public:
        IndiaParinam()
        {
            x = 0;
            y = 0; 
        }
        IndiaParinam(int xx, int yy)
        {
            x = xx;
            y = yy; 
        }
        IndiaParinam(IndiaParinam *objB)
        {
            x = objB->x;
            y = objB->y; 
        }
        void Display()
        {
            cout<< x << " " << y;
        }
};
int main()
{
    IndiaParinam objParinam( new IndiaParinam(20, 40) );
    objParinam.Display();
    return 0; 
}


A). The program will print the output 0 0 .
B). The program will print the output 20 40 .
C). The program will print the output Garbage Garbage .
D). The program will report compile time error.
Answer : Option B

Question 19 :

What will be the out of the following program?

#include < iostream . h > 
class ParinamBase
{
    public:
    int x, y; 
    public:
    ParinamBase(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy; 
    } 
 };
class ParinamDerived : public ParinamBase
{
    private:
        ParinamBase objBase; 
    public:
    ParinamDerived(int xx, int yy) : ParinamBase(xx), objBase(yy)
    {
        cout << this->x   << " " 
             << this->y   << " "  
             << objBase.x << " "
             << objBase.y << " ";
    } 
    ~ParinamDerived()
    { }
};
int main()
{
    ParinamDerived objDev(11, 22); 
    return 0;
}


A). 11 22 0 0
B). 11 0 0 22
C). 11 0 22 0
D). 11 22 11 22
E). The program will report compile time error.
Answer : Option C

Question 20 :

What will be the out of the following program?

#include < iostream . h > 
class ParinamBase
{
    public:
    int x, y; 
    public:
    ParinamBase(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy; 
    } 
 };
class ParinamDerived : public ParinamBase
{
    private:
        ParinamBase objBase; 
    public:
    ParinamDerived(int xx, int yy) : ParinamBase(xx), objBase(yy)
    {
        cout << x          << " " 
             << this->x    << " "  
             << ParinamBase::x << " "     
             << this->objBase.x ;
    } 
    ~ParinamDerived()
    { }
};
int main()
{
    ParinamDerived objDev(11, 22); 
    return 0;
}


A). 11 22 0 0
B). 11 11 0 22
C). 11 11 11 0
D). 11 11 11 22
E). The program will report compile time error.
Answer : Option D