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; 
}
The program will print the output 0.
The program will print the output 33.
The program will print the output Garbage.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
19 comments Page 2 of 2.

Jitendra said:   5 years ago
No. Only static functions can access static members.

Pooja said:   1 decade ago
No. Only static functions can access static members.

Abhay fegade said:   1 decade ago
Non static method can also access the static data.
(1)

Gangadharreddy said:   1 decade ago
Statics members are accessed by static functions.

Dhaval said:   1 decade ago
Non static method can't access static member!

Gaurav said:   1 decade ago
Because display is called without any object.

Kajju said:   9 years ago
int IndiaBix::x = 0; How to interpret this?
(1)

Abcd said:   9 years ago
There is no object to use class members.
(1)

Nikita said:   1 decade ago
Why is it compile time error ?


Post your comments here:

Your comments will be displayed after verification.