CPP > Random > Beginner Next/Skip this question

What will be the output of the following C++ program calling constructor explicitly?

#include <iostream>
using namespace std;

class MyClass
    //constructor with zero parameter, also known as default contructor for a class
    public: MyClass(int a, int b)
        this->a = a;
        this->b = b;
    //Whenever this contructor is called, this will call the constructor accepting 2 int type arguments.
    public: MyClass(int a) : MyClass(a, a)
    public: int a;
    public: int b;
    public: int add()
        return this->a + this->b;

int main () {
    MyClass m(10);
    cout << m.add();
    return 0;
Answers :
social share share on facebook share on twitter share on google plus share on linkedin
Add Comments :



Next Question