C++ | Constructors | Question 3

Output of following program?

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


(A) Compiler Error
(B) Runtime Error
(C) Constructor called


Answer: (A)

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



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.