Examveda

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class sample;
class sample1 
{
    int width, height;
    public:
    int area ()
    {
        return (width * height);}
        void convert (sample a);
    };
class sample 
{
    private:
    int side;
    public:
    void set_side (int a)
    { 
        side = a;
    }
    friend class sample1;
};
void sample1::convert (sample a) 
{
    width = a.side;
    height = a.side;
}
int main () 
{
    sample sqr;
    sample1 rect;
    sqr.set_side(6);
    rect.convert(sqr);
    cout << rect.area();
    return 0;
}

A. 24

B. 35

C. 16

D. 36

Answer: Option D


Join The Discussion

Related Questions on Classes and Objects in C plus plus