What is the difference between a static variable and a dynamic variable in java/oops?

前端 未结 8 832
情话喂你
情话喂你 2021-01-28 12:22

please someone tell me the difference between a \'static variable\' and a \'normal variable\' in oops or in java. Also their usage if possible.

8条回答
  •  孤城傲影
    2021-01-28 13:01

    Static variables are those which are at the class or type level. And there will be only one copy of it is available to the all instances of that class type.

    And there is no concept of dynamic variables as for as i know. If you came across about this concept at some particular context then mention that, might be helpful to explain you.

    EDITED : to answer your question of difference between 'static int' and 'int'.

    Say suppose you have a class as

               public class StaticInfo{
    
                private static int count;
                private int variable;
                //.. say setter and getters for variable
                //.. static setter and getters for count;
              }
    

    So if you create 2 objects of the type StaticInfo then these two will have two different 'variable' member but one common count member which is a class member.

    hope it is clear now.

提交回复
热议问题