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 8 of 24

Explore more Topics under Object Oriented Programming Using C++

Q71.
What is the output of this program?
    #include <iostream>
    using namespace std;
    template <class T>
    inline T square(T x)
    {
        T result;
        result = x * x;
        return result;
    };
    template <>
    string square<string>(string ss)
    {
        return (ss+ss);
    };
    int main()
    {
        int i = 2, ii;
        string ww("A");
        ii = square<int>(i);
        cout << i << ": " << ii;
        cout << square<string>(ww) << ":" << endl;
    }
Discuss
Answer: (a).2:4AA
Q72.
What is the output of this program?
    #include <iostream>
    using namespace std;
    template <typename T = float, int count = 3>
    T multIt(T x)
    {
        for(int ii = 0; ii < count; ii++)
        {
            x = x * x;
        }
        return x;
    };
    int main()
    {
        float xx = 2.1;
        cout << xx << ": " << multIt<>(xx) << endl;
    }
Discuss
Answer: (c).2.1: 378.228
Q73.
What is the output of this program?
    #include <iostream>
    #include <string>
    #include <cstring>
    using namespace std;
    template <class type>
    type MyMax(const type Var1, const type Var2)
    {
        cout << "no specialization";
        return Var1 < Var2 ? Var2 : Var1;
    }
    template <>
    const char *MyMax(const char *Var1, const char *Var2)
    {
        return (strcmp(Var1, Var2)<0) ? Var2 : Var1;
    }
    int main()
    {
        string Str1 = "class", Str2 = "template";
        const char *Var3 = "class";
        const char *Var4 = "template";
        const char *q = MyMax(Var3, Var4);
        cout << q << endl;
        return 0;
    }
Discuss
Answer: (a).template
Q74.
What is the output of this program?
    #include <iostream>
    using namespace std;
    template<class T = float, int i = 5> class A
    {
        public:
        A();
        int value;
    };
    template<> class A<> 
    { 
        public: A(); 
    };
    template<> class A<double, 10>
    { 
        public: A(); 
    };
    template<class T, int i> A<T, i>::A() : value(i)
    {
        cout << value;
    }
    A<>::A() 
    {
        cout << "default";
    }
    A<double, 10>::A() 
    {
        cout << "10" << endl;
    }
    int main() 
    {
        A<int, 6> x;
        A<> y;
        A<double, 10> z;
    }
Discuss
Answer: (c).6default10
Q75.
How many types of specialization are there in c++?

a.

1

b.

2

c.

3

d.

4

Discuss
Answer: (b).2
Discuss
Answer: (a).explicit specialization
Q77.
Which is dependant on template parameter?
Discuss
Answer: (a).base class
Discuss
Answer: (b).default type values
Q79.
How many bits of memory needed for internal representation of class?
Discuss
Answer: (d).no memory needed
Q80.
What is the output of this program?
    #include <iostream>
    using namespace std;
    class class0 
    {
        public:
        virtual ~class0(){}
        protected:
        char p;
        public:
        char getChar();
    };
    class class1 : public class0 
    {
        public:
        void printChar();
    };
    void class1::printChar()
    {
        cout  << "True" << endl;
    }
    int main() 
    {
        class1 c;
        c.printChar();
        return 1;
    }
Discuss
Answer: (a).True

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!