+ 2
What is the difference between static and non-static data members?
4 Answers
+ 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