C++ Programming - Objects and Classes - Discussion
Discussion Forum : Objects and Classes - Programs (Q.No. 2)
2.
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;
}
void Display()
{
cout<< x ;
}
};
int IndiaBix::x = 0;
int main()
{
IndiaBix::SetData(33);
IndiaBix::Display();
return 0;
}Discussion:
19 comments Page 1 of 2.
Dixit said:
1 decade ago
Can not call display() function without object! Because display() is not declared static.
(1)
Jitendra said:
6 years ago
No. Only static functions can access static members.
(1)
Abcd said:
10 years ago
There is no object to use class members.
(1)
Kajju said:
10 years ago
int IndiaBix::x = 0; How to interpret this?
(1)
Abhay fegade said:
1 decade ago
Non static method can also access the static data.
(1)
Komal said:
1 decade ago
We cannot use scope resolution operator in main function.
(1)
Gangadharreddy said:
1 decade ago
Statics members are accessed by static functions.
Madhav said:
1 decade ago
Because display is not a static function, it cannot be accessed by class name.
Kowsik said:
1 decade ago
Replace int main() part by following Code.
int main()
{
IndiaBix obj;
obj.SetData(33);
obj.Display();
return 0;
}
Output : 33
int main()
{
IndiaBix obj;
obj.SetData(33);
obj.Display();
return 0;
}
Output : 33
Nikita said:
1 decade ago
Why is it compile time error ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers