23.1k views
3 votes
What is the output of the following program? #include using namespace std; class TestClass { private: int val; void showVal() { cout << val << endl; } public: TestClass(int x) { val = x; } }; int main() { TestClass test(77); test.showVal(); return 0; }

1 Answer

5 votes

Answer:

The answer to this question is "The program will not compile."

Step-by-step explanation:

In the given C++ programming language program. The program will not compile because in the program we define a class that is "TestClass" in this class we define a private variable and a function that is val and showVal(). In this function, we print the value of val variable. Then we define a parameterized constructor, in this constructor we use the private variable val that holds the constructor parameter value. Then we define a main function, in the main function we create a class object test which is defined wrong.

That's why the answer to this question is "The program will not compile."

User Mikah
by
6.9k points