-
What is the output of this program?
#include
using namespace std;
class Example
{
private:
int num;
public:
void input()
{
cout << num;
}
void Result()
{
cout << "Entered Variable is: ";
cout << num << "\n";
}
};
int main()
{
Example obj;
obj.input();
obj.Result();
obj.num();
return 0;
}
-
- Runtime Error
- Garbage value
- Compilation Error
- Entered Variable is: 15
- None of these
Correct Option: C
While using private member, you can’t access it variable.
Compilation Error
In function 'int main()':
6:13: error: 'int Example::num' is private
23:13: error: within this context
23:17: error: expression cannot be used as a function