adplus-dvertising

Welcome to the Classes and Operator Overloading in C++ MCQs Page

Dive deep into the fascinating world of Classes and Operator Overloading in C++ with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Classes and Operator Overloading in C++, a crucial aspect of Object Oriented Programming Using C++. In this section, you will encounter a diverse range of MCQs that cover various aspects of Classes and Operator Overloading in C++, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Object Oriented Programming Using C++.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Classes and Operator Overloading in C++. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Object Oriented Programming Using C++.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Classes and Operator Overloading in C++. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Classes and Operator Overloading in C++ MCQs | Page 34 of 39

Explore more Topics under Object Oriented Programming Using C++

Q331.
What will be the output of the following program?
#include<iostream.h> 
class BitsBase
{
    public:
        float x; 
}; 
class BitsDerived : public BitsBase
{
    public: 
        char ch; 
        void Process()
        {
            ch = (int)((x=12.0)/3.0);
        }
        void Display()
        {
            cout<< (int)ch;
        } 
}; 
int main()
{
    class BitsDerived  *objDev = new BitsDerived;
    objDev->Process();
    objDev->Display();
    return 0; 
}
Discuss
Answer: (a).The program will print the output 4.
Q332.
Which of the following statement is correct about the program given below?
#include<iostream.h>
#include<process.h> 
class Compscibits
{
    static int x; 
    public:
    Compscibits()
    {
        if(x == 1)
            exit(0); 
        else
            x++;
    }
    void Display()
    {
        cout<< x << " ";
    }
};
int Compscibits::x = 0; 
int main()
{
    Compscibits objBits1; 
    objBits1.Display(); 
    Compscibits objBits2; 
    objBits2.Display(); 
    return 0; 
}
Discuss
Answer: (d).The program will print the output 1.
Q333.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class BitsBase
{
    int x, y; 
    public:
    BitsBase(int xx = 10, int yy = 10)
    {
        x = xx;
        y = yy;
    }
    void Show()
    {
        cout<< x * y << endl;
    }
};
class BitsDerived
{
    private:
        BitsBase objBase; 
    public:
    BitsDerived(int xx, int yy) : objBase(xx, yy)
    {
        objBase.Show();
    }
};
int main()
{
    BitsDerived objDev(10, 20);
    return 0; 
}
Discuss
Answer: (b).The program will print the output 200.
Q334.
What will be the output of the following program?
#include<iostream.h> 
class BitsBase
{
    int x, y; 
    public:
    BitsBase(int xx = 10, int yy = 10)
    {
        x = xx;
        y = yy;
    }
    void Show()
    {
        cout<< x * y << endl;
    }
};
class BitsDerived : public BitsBase
{
    private:
        BitsBase objBase; 
    public:
    BitsDerived(int xx, int yy) : BitsBase(xx, yy)
    {
        objBase.Show();
    }
};
int main()
{
    BitsDerived objDev(10, 20);
    return 0; 
}#include<iostream.h> 
class A
{
    public:
    void BitsFunction(void)
    {
        cout<< "Class A" << endl;
    }
};
class B: public A
{
    public:
    void BitsFunction(void)
    {
        cout<< "Class B" << endl;
    } 
};
class C : public B
{
    public:
    void BitsFunction(void)
    {
        cout<< "Class C" << endl;
    } 
};
int main()
{
    A *ptr;
    B objB;
    ptr = &objB;
    ptr = new C();
    ptr->BitsFunction();
    return 0; 
}
Discuss
Answer: (a).Class A.
Q335.
What will be the output of the following program?
#include<iostream.h> 
class BitsBase
{
    int x, y; 
    public:
    BitsBase(int xx = 10, int yy = 10)
    {
        x = xx;
        y = yy;
    }
    void Show()
    {
        cout<< x * y << endl;
    }
};
class BitsDerived : public BitsBase
{
    private:
        BitsBase objBase; 
    public:
    BitsDerived(int xx, int yy) : BitsBase(xx, yy), objBase(yy, yy)
    {
        objBase.Show();
    }
};
int main()
{
    BitsDerived objDev(10, 20);
    return 0; 
}#include<iostream.h> 
class Point
{
    int x, y; 
    public:
    Point(int xx = 10, int yy = 20)
    {
        x = xx;
        y = yy; 
    }
    Point operator + (Point objPoint)
    {
        Point objTmp;
        objTmp.x = objPoint.x + this->x; 
        objTmp.y = objPoint.y + this->y;
        return objTmp;
    }
    void Display(void)
    {
        cout<< x << " " << y;
    }
};
int main()
{
    Point objP1;
    Point objP2(1, 2);
    Point objP3 = objP1 + objP2;
    objP3.Display(); 
    return 0; 
}
Discuss
Answer: (c).11 22
Q336.
What will be the output of the following program?
#include<iostream.h>
#include<string.h> 
class Compscibits
{
    char str[50]; 
    char tmp[50]; 
    public:
    Compscibits(char *s)
    {
        strcpy(str, s);
    }
    int BitsFunction()
    {
        int i = 0, j = 0; 
        while(*(str + i))
        {
            if(*(str + i++) == ' ')
                *(tmp + j++) = *(str + i);
        }
        *(tmp + j) = 0; 
        return strlen(tmp); 
    }
};
int main()
{
    char txt[] = "Welcome to Compscibits.com!";
    Compscibits objBits(txt); 
    cout<< objBits.BitsFunction();
    return 0;
}
Discuss
Answer: (b).2
Q337.
When an object goes out of scope, which function is called automatically?
Discuss
Answer: (b).Destructor
Q338.
Destructors do not receive parameters and do not
Discuss
Answer: (a).Return values
Q339.
Scope resolution operator is denoted by
Discuss
Answer: (b).: :
Q340.
A class data members and member functions belongs to
Discuss
Answer: (c).That class scope

Suggested Topics

Are you eager to expand your knowledge beyond Object Oriented Programming Using C++? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!