adplus-dvertising

Welcome to the Derived Classes,Templates and Exception Handling in C++ MCQs Page

Dive deep into the fascinating world of Derived Classes,Templates and Exception Handling in C++ with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Derived Classes,Templates and Exception Handling 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 Derived Classes,Templates and Exception Handling 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 Derived Classes,Templates and Exception Handling 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 Derived Classes,Templates and Exception Handling in C++. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Derived Classes,Templates and Exception Handling in C++ MCQs | Page 2 of 24

Q11.
Which is also called as abstract class?
Discuss
Answer: (b).pure virtual function
Q12.
What is the output of this program?
    #include <iostream>
    using namespace std;
    class p 
    {
        protected:
        int width, height;
        public:
        void set_values (int a, int b)
        {
            width = a; height = b; 
        }
        virtual int area (void) = 0;
    };
    class r: public p
    {
        public:
        int area (void)
        { 
            return (width * height);
        }
    };
    class t: public p 
    {
        public:
        int area (void)
        {
            return (width * height / 2); 
        }
    };
    int main () 
    {
        r rect;
        t trgl;
        p * ppoly1 = &rect;
        p * ppoly2 = &trgl;
        ppoly1->set_values (4, 5);
        ppoly2->set_values (4, 5);
        cout << ppoly1 -> area() ;
        cout << ppoly2 -> area();
        return 0;
    }
Discuss
Answer: (d).2010
Q13.
What is the output of this program?
    #include <iostream>
    using namespace std;
    class MyInterface 
    {
        public:
        virtual void Display() = 0;
    };
    class Class1 : public MyInterface 
    {
        public:
        void Display() 
        {
            int  a = 5;
            cout << a;
        }
    };
    class Class2 : public MyInterface 
    {
        public:
        void Display()
        {
            cout <<" 5" << endl;
        }
    };
    int main()
    {
        Class1 obj1;
        obj1.Display();
        Class2 obj2;
        obj2.Display();
        return 0;
    }
Discuss
Answer: (c).5 5
Q14.
What is the output of this program?
    #include <iostream>
    using namespace std;
    class sample
    {
        public:
        virtual void example() = 0; 
    };
    class Ex1:public sample
    {
        public:
        void example()
        {
            cout << "ubuntu";
        }
    };
    class Ex2:public sample
    {
        public:
        void example()
        {
            cout << " is awesome";
        }
    };
    int main()
    {
        sample* arra[2];
        Ex1 e1;
        Ex2 e2;
        arra[0]=&e1;
        arra[1]=&e2;
        arra[0]->example();
        arra[1]->example();
    }
Discuss
Answer: (c).ubuntu is awesome
Q15.
What is the output of this program?
    #include <iostream>
    using namespace std;
    class Base
    {
        public:
        virtual void print() const = 0;
    };
    class DerivedOne : virtual public Base
    {
        public:
        void print() const
        {
            cout << "1";
        }
    };
    class DerivedTwo : virtual public Base
    {
        public:
        void print() const
        {
            cout << "2";
        }
    };
    class Multiple : public DerivedOne, DerivedTwo
    {
        public:
        void print() const
        {
            DerivedTwo::print();
        }
    };
    int main()
    {
        Multiple both;
        DerivedOne one;
        DerivedTwo two;
        Base *array[ 3 ];
        array[ 0 ] = &both;
        array[ 1 ] = &one;
        array[ 2 ] = &two;
        for ( int i = 0; i < 3; i++ )
        array[ i ] -> print();
        return 0;
    }
Discuss
Answer: (b).212
Discuss
Answer: (a).Function which does not have definition of its own
Discuss
Answer: (a).We cannot make an instance of an abstract base class
Discuss
Answer: (a).base class only
Q19.
Which interface determines how your class will be used by other program?
Discuss
Answer: (a).public
Discuss
Answer: (a).Overriding refers to a derived class function that has the same name and signature as a base class virtual function
Page 2 of 24

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!