Create a class named TestClass that holds a single private integer field and a public constructor. The only statement in the constructor is one that displays the message “Constructing”. Write a main()function that instantiates one object of the TestClass. Save the file as TestClass.cpp in the folder. Run the program and observe the results
#include<iostream>
using namespace std;
class TestClass{
private:
int x;
public:
TestClass(){
cout<<"Constructing";
}
};
int main(){
TestClass p; //p is the object of class
}
Output of following program is after run and save by name TestClass.cpp:
Constructing
Comments
Leave a comment