C++ Programming - Objects and Classes - Discussion
Discussion Forum : Objects and Classes - Programs (Q.No. 13)
13.
Which of the following statement is correct about the program given below?
#include<iostream.h>
#include<process.h>
class IndiaBix
{
static int x;
public:
IndiaBix()
{
if(x == 1)
exit(0);
else
x++;
}
void Display()
{
cout<< x << " ";
}
};
int IndiaBix::x = 0;
int main()
{
IndiaBix objBix1;
objBix1.Display();
IndiaBix objBix2;
objBix2.Display();
return 0;
}
Discussion:
13 comments Page 2 of 2.
Shradha said:
7 years ago
Here, x is static, then how display() can access it. The answer needs to be compile time error.
Tejas B said:
4 years ago
Thanks @Rashmi.
Sameer said:
3 years ago
No, the Static function of a class in C++ cannot access non-static variables, but, it can access static variable only. However, non-static member function can access static and non-static variable both.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers