+ 2
What is the difference between static and non-static data members?
4 ответов
+ 8
A non-static member is unique for each object and a static member is not.
For example, if I were to define a class named “Cat” with a static member, “numOfCats” and a non-static member, “height”:
Cat c1 = new Cat();
Cat c2 = new Cat();
c1.height = 5;
c2.height = 7;
//they each have their own height.
Cat.numOfCats = 1;
Cat.numOfCats++;
//numOfCats is shared by all cats, and is accessed through the class name instead of the object name.
+ 1
@VIJAY JAGADHANE
You’re thinking of final keyword.
- 2
static is fix value and nan static change value