C++ Programming - Objects and Classes - Discussion
Discussion Forum : Objects and Classes - Programs (Q.No. 3)
3.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
static int x;
public:
static void SetData(int xx)
{
x = xx;
}
static void Display()
{
cout<< x ;
}
};
int IndiaBix::x = 0;
int main()
{
IndiaBix::SetData(44);
IndiaBix::Display();
return 0;
}
Discussion:
5 comments Page 1 of 1.
Yash chavan said:
7 years ago
int IndiaBix::x = 0;
How can it be works?
How can it be works?
Rajput said:
1 decade ago
How can be static variable initialized two times ? please explain.
Rits said:
1 decade ago
But x is static so it should be initialized once. So it should display 0?
DHANUNJAY said:
1 decade ago
Because he not the matter about private member or public member here just using both are static functions so directly call and display the result.
Ysr said:
1 decade ago
Why not it is giving error for accessing private member x?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers