ObjectiveMcq
Print Protected
This page is protected for print. Use the website to view the content.
What will be the output of the following C++ code
#include <iostream>
using namespace std;
class A{
public:
int a;
A(int a){
this->a = a;
}
};
int main(int argc, char const *argv[])
{
A aa2(10);
cout<<a2.a;
return}
Correct Answer: B — Compile time error
The declaration of object a1 needs a constructor without any arguments which is not available in the class as we have overwritten the default constructor, therefore, the program gives the error.