Open In App

C++ | Constructors | Question 3

Output of following program? 
 




#include <iostream>
using namespace std;
 
class Point {
    Point() { cout << "Constructor called"; }
};
 
int main()
{
    Point t1;
    return 0;
}

(A)

Runtime Error

(B)

None of these

(C)

Constructor called

(D)

Compiler Error


Answer: (D)
Explanation:

By default all members of a class are private. Since no access specifier is there for Point(), it becomes private and it is called outside the class when t1 is constructed in main. 
 

Quiz of this Question
Please comment below if you find anything wrong in the above post

Article Tags :