Classes & Objects


  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class BaseClass
    {
    public:
    BaseClass(){}
    ~BaseClass(){}
    protected:
    private:
    };
    class DerivedClass:public BaseClass
    {
    public:
    DerivedClass(){}
    DerivedClass(){}
    private:
    protected:
    };
    int main()
    {
    cout << "The program exceuted" << endl;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Compilation Error

    error: 'DerivedClass::DerivedClass()' cannot be overloaded
    error: with 'DerivedClass::DerivedClass()'


  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class ExceptionClass
    {
    public:
    ExceptionClass(int value) : mValue(value)
    {
    }
    int mValue;
    };
    class DerivedExceptionClass : public ExceptionClass
    {
    public:
    DerivedExceptionClass(int value, int anotherValue) : ExceptionClass(value),mAnotherValue(anotherValue)
    {
    }
    int mValue;
    int mAnotherValue;
    };
    void doSomething()
    {
    throw DerivedExceptionClass(10,20);
    }
    int main()
    {
    try
    {
    doSomething();
    }
    catch (DerivedExceptionClass &exception)
    {
    cout << "Caught Derived Class Exception";
    }
    catch (ExceptionClass &exception)
    {
    cout << "Caught Base Class Exception";
    }
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    As we are throwing the value from the derived class, it is arising an exception in derived class



  1. What is the output of this program?
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
    string str = "Interview Mania";
    str.insert(str.size() / 3, " * ");
    cout << str << endl;
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    In this program, We are placing the string based on the size of the string and it is a string hierarchy.


  1. How many types of guarantees are there in exception class can have?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    There are three types of guarantees in c++. They are weak, strong and no-throw.



  1. Which operator is used to create the user-defined streams in c++?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    We can make user-defined types with streams by overloading the insertion operator (<<) to put objects into streams and the extraction operator (>>) to read objects from streams.