Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

C++ | Constructors | Question 3

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Output of following program? 
 

C++




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

(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

My Personal Notes arrow_drop_up
Last Updated : 02 Dec, 2021
Like Article
Save Article
Similar Reads