C++ Programming - Objects and Classes - Discussion

Discussion Forum : Objects and Classes - General Questions (Q.No. 12)
12.
Which of the following type of data member can be shared by all instances of its class?
Public
Inherited
Static
Friend
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
10 comments Page 1 of 1.

NimRasker said:   5 years ago
What is the exact different between static and public? Are they both can be accessed in any where of the code? please help me.

Ravenna said:   8 years ago
Thanks for the explanation @Ron.

Ron said:   9 years ago
Suppose we declare a class data member as static, it means that we have created only one copy of that member which will be shared by all objects that we create rather than each object having its individual copy of the data member. Instances are nothing but all the objects that we create from a class.

For eg;
class eg
{
static int a;
};
int eg::a=1;

Now, if we create objects using this class, the value will be available for all the objects which is not possible without using static. I hope this solves.

Nikita rana said:   10 years ago
Give me exact answer.

Nandhini said:   10 years ago
Static data type is fixed and it cannot be changed. Then how we share by all instance in class? How it is possible?

Darshan said:   1 decade ago
Can anyone tell me the exact difference between static and public?

Pankaj sharma said:   1 decade ago
If I am not mistaken the question is about sharing a common data member by all instances of the class so the answer is correct.
(1)

Atul sharma said:   1 decade ago
I think public are the ones which could be used anywhere. (as the name suggests).

Static are those whose value are predefined in respect to static and dynamic functions.

Honey said:   1 decade ago
What is the difference between public and static?

Shobhit said:   1 decade ago
Static data members can be accessed by all instances of a class.

Post your comments here:

Your comments will be displayed after verification.