Find the errors in the following program and correct them.
[Assume the necessary header files and namespaces included
class test
{ static int x;
int y;
public:
test( ){x=0;y=0;}
static void display()
{ cout<<x<<”\t”<<y<<endl; }
void output()
{cout<<x<<”\t”<<y<<endl;}
};
int main()
{ test T1;
T1.display();
test::output();
return 0;
}
Errors
Invalid use of static keyword
Invalid use of member test::y
Cannot call member function void test::output(); without an object.
The corrected code:
#include<iostream>
using namespace std;
class test
{
private:
int x;
int y;
public:
test( ){
x=0;
y=0;
}
void display()
{
cout<<x<<"\t"<<y<<endl;
}
void output()
{
cout<<x<<"\t"<<y<<endl;
}
};
int main()
{ test T1;
T1.display();
T1.output();
return 0;
}
Comments
Leave a comment