Open In App
Related Articles

C++ | Constructors | Question 3

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Output of following program? 
 

C++

#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

Last Updated : 02 Dec, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads