My Report

C++ Classes Test – 1


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Which is used to define the member of a class externally?

2. Constructors are used to ____________

3. When struct is used instead of the keyword class means, what will happen in the program?

4. The data members and functions of a class in C++ are by default ____________

5. Which of the following is a valid class declaration?

6. How many specifiers are present in access specifiers in class?

7. Which other keywords are also used to declare the class other than class?

8. What will be the output of the following C++ code?

    #include <iostream>
    using namespace std;
    class rect
    {
        int x, y;
        public:
        void val (int, int);
        int area ()
        {
            return (x * y);
        }
    };
    void rect::val (int a, int b)
    {
        x = a;
        y = b;
    }
    int main ()
    {
        rect rect;
        rect.val (3, 4);
        cout << "rect area: " << rect.area();
        return 0;
    } 

9. What will be the output of the following C++ code?

    #include <iostream>
    using namespace std;
    class CDummy
    {
        public:
        int isitme (CDummy& param);
    };
    int CDummy::isitme (CDummy& param)
    {
        if (&param == this)
            return true;
        else
            return false;
    }
    int main ()
    {
        CDummy a;
        CDummy *b = &a;
        if (b->isitme(a)) 
        {
            cout << "execute";
        }
        else
        {
            cout<<"not execute";
        }
        return 0;
    } 

10. What does a class in C++ holds?


 

Start practicing “1000 MCQs on C++”, and once you are ready, you can take tests on all topics by attempting our “C++ Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.