what is a static instance variable code example

Example 1: Static and Instance Variable?

Different is number of the copies are different.
Instance are belongs to object from one class 
you can have multiple objects. If u have multiple 
objects and if you want to each of the object a own 
value that is time you need to use instance variable.
If you want to all object have same value, you will use static. 
Static is a global and you can call anywhere. 
Static run only 1 time. 1 copy.
Static block – Instance Block what difference between them? 
Both of them initializing static and instance variables.
Static Block if it takes multiple steps, you can use static block.
Get the file, read the file, set the variable. 
You can set these 3 steps In the Block, once. 
Complete the multiple steps one time. 
Instance Block; it is going to run depend of the object. 
If you have 10 object it is going to run 10 times.

Example 2: what is static variable

The static variable is used to refer to the common property of all objects 
(that is not unique for each object), 
e.g., The company name of employees, college name of students, etc. 
Static variable gets memory only once in the class area at the time of 
class loading. Using a static variable makes your program more 
memory efficient (it saves memory). Static variable belongs to the class 
rather than the object.

Tags:

Misc Example