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 33 of 39

Explore more Topics under Object Oriented Programming Using C++

Discuss
Answer: (c).Member function and data are by default public in structures but private in classes.
Discuss
Answer: (d).The program reports linker error.
Q323.
Which of the following statements are correct for a static member function?
1. It can access only other static members of its class.
2. It can be called using the class name, instead of objects.
Discuss
Answer: (c).Both 1 and 2 are correct.
Q324.
What will be the output of the following program?
#include<iostream.h> 
class Bits
{
    public:
      int x;
};
int main()
{
    Bits *p = new Bits();

    (*p).x = 10;
    cout<< (*p).x << " " << p->x << " " ;

    p->x = 20;
    cout<< (*p).x << " " << p->x ;

    return 0;
}
Discuss
Answer: (a).10 10 20 20
Q325.
What will be the output of the following program?
#include<iostream.h> 
class Compscibits
{
    static int x; 
    public:
    static void SetData(int xx)
    {
        x = xx; 
    }
    void Display() 
    {
        cout<< x ;
    }
};
int Compscibits::x = 0; 
int main()
{
    Compscibits::SetData(33);
    Compscibits::Display();
    return 0; 
}#include<iostream.h> 
class Compscibits
{
    static int x; 
    public:
    static void SetData(int xx)
    {
        x = xx; 
    }
    static void Display() 
    {
        cout<< x ;
    }
};
int Compscibits::x = 0; 
int main()
{
    Compscibits::SetData(44);
    Compscibits::Display();
    return 0; 
}#include<iostream.h> 
class BitsTeam
{
    int x, y; 
    public:
    BitsTeam(int xx)
    {
        x = ++xx;
    }
    void Display()
    {
        cout<< --x << " ";
    }
};
int main()
{
    BitsTeam objBT(45);
    objBT.Display();
    int *p = (int*)&objBT;
    *p = 23;
    objBT.Display();
    return 0; 
}
Discuss
Answer: (a).45 22
Q326.
What will be the output of the following program?
#include<iostream.h> 
class Compscibits
{
    static int x; 
    public:
    static void SetData(int xx)
    {
        this->x = xx; 
    }
    static void Display() 
    {
        cout<< x ;
    }
};
int Compscibits::x = 0; 
int main()
{
    Compscibits::SetData(22);
    Compscibits::Display();
    return 0; 
}#include<iostream.h> 
class CompSci
{
    public:
    struct Bits
    {
        int   x;
        float y;
        void Function(void)
        {
            y = x = (x = 4*4); 
            y = --y * y;
        }
        void Display()
        {
            cout<< y << endl;
        } 
    }B; 
}I; 
int main()
{
    I.B.Display(); 
    return 0;
}
Discuss
Answer: (a).0
Q327.
What will be the output of the following program?
#include<iostream.h>
#include<string.h> 
class Compscibits
{
    int val; 
    public:
    void SetValue(char *str1, char *str2)
    {
        val = strcspn(str1, str2);
    }
    void ShowValue()
    {
        cout<< val;
    } 
};
int main() 
{
    Compscibits objBits;
    objBits.SetValue((char*)"CompSci", (char*)"Bits"); 
    objBits.ShowValue(); 
    return 0; 
}

a.

2

b.

3

c.

5

d.

8

Discuss
Answer: (b).3
Q328.
Which of the following statement is correct about the program given below?
#include<iostream.h>
#include<string.h> 
class Compscibits
{
    public:
    void GetData(char *s, int x, int y )
    {
        int i = 0;
        for (i = x-1; y>0; i++)
        {
            cout<< s[i];
            y--; 
        } 
    }
}; 
int main()
{
    Compscibits objBits;
    objBits.GetData((char*)"Welcome!", 1, 3);
    return 0; 
}
Discuss
Answer: (b).The program will print the output Wel.
Q329.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class BitsData
{
    int x, y, z; 
    public:
    BitsData(int xx, int yy, int zz)
    {
        x = ++xx;
        y = ++yy;
        z = ++zz;
    }
    void Show()
    {
        cout<< "" << x++ << " " << y++ << " " << z++;
    } 
}; 
int main()
{
    BitsData objData(1, 2, 3);
    objData.Show();
    return 0; 
}#include<iostream.h> 
class Compscibits
{
    int x; 
    float y; 
    public:
    void Function()
    {
        x = 4; 
        y = 2.50; delete this;
    }
    void Display()
    {
        cout<< x << " " << y;
    } 
}; 
int main()
{
    Compscibits *pBits = new Compscibits();
    pBits->Function(); 
    pBits->Function(); 
    pBits->Display(); 
    return 0; 
}
Discuss
Answer: (c).The program will report runtime error.
Q330.
What will be the output of the following program?
#include<iostream.h> 
class Compscibits
{
    static int count; 
    public:
    static void First(void)
    {
        count = 10;
    }
    static void Second(int x)
    {
        count = count + x; 
    }
    static void Display(void)
    {
        cout<< count << endl;
    } 
};
int Compscibits::count = 0; 
int main()
{
    Compscibits :: First();
    Compscibits :: Second(5);
    Compscibits :: Display();
    return 0; 
}
Discuss
Answer: (d).15

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!