Examveda

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class sample
{
    private:
    int var;
    public:
    void input()
    {
       cout << var;
    }
    void output()
    {
       cout << "Variable entered is ";
       cout << var << "\n";
    }
};
int main()
{
    sample object;
    object.input();
    object.output();
    object.var();
    return 0;
}

A. Enter an integer 5
Variable entered is 5

B. Runtime error

C. Error

D. Enter an integer 7
Variable entered is 7

Answer: Option C


Join The Discussion

Related Questions on Classes and Objects in C plus plus