Computer Science · C++ Programming - Access Specifiers
What will happen when the following C++ program is compiled and executed? #include using namespace std; class Demo { int x; public: void set(int a) { x = a; } void display() { cout << x; } }; int main() { Demo d; d.x = 10; d.display(); }
- 1Prints 10
- 2Undefined behavior
- 3Compilation error due to accessing a private member✓
- 4Prints a garbage value
Correct answer
Compilation error due to accessing a private member
Download Single Question PDF
Save this question and verified answer as a clean study sheet with live clickable link.
Share with Friends & Study Groups
Challenge your peer aspirants on WhatsApp or Telegram to solve this question!
Preparing for Computer Science?
Practice full-length mock tests with real exam timers, instant score analysis, and all-India ranking.
Want more practice questions on C++ Programming - Access Specifiers?
Solve complete topic-wise tests with detailed solutions on GkGet.
Related Practice Questions
Recommended practice questions in Computer Science · C++ Programming - Access Specifiers