C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 55)
55.
What is correct about the static data member of a class?
A static member function can access only static data members of a class.
A static data member is shared among all the object of the class.
A static data member can be accessed directly from main().
Both A and B.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
7 comments Page 1 of 1.

Gnanasundaram said:   7 years ago
Excellent explanation. Thanks all.

Hithes said:   8 years ago
Answer is all of the above,

We can access a static member function directly with the scope resolution operator (::).
ex:

class A
{
static void function() { ........ }
bla bla bla
}
int main()
{
cout << A::function();
return 0;
}
(1)

Vikash said:   8 years ago
I think answer should be all of the above.

Vijay said:   10 years ago
Answer is option D because both A & B are true.

ChandraMohan said:   1 decade ago
In java main method also a static method right. There we can access the static members directly then why it is wrong here.

Example:

public class A{
static void m1(){
//statements
}
public static void main(String ar[]){
m1();
}
}

Roshan bisoi said:   1 decade ago
Can main access a static member if the class is declared protected?

Madison said:   1 decade ago
The answer should be all of the above. You can have main access static data directly.

class a
{
public:
static int x;
};

int a::x = 5;

main (int argc, char** argv)
{
std::cout << a::x;
}

Post your comments here:

Your comments will be displayed after verification.