Ask Question
30 September, 17:31

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; }

+5
Answers (1)
  1. 30 September, 17:43
    0
    The answer to this question is "The program will not compile."

    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."
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “What is the output of the following program? #include using namespace std; class TestClass { private: int val; void showVal () { cout ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers