Difference between Static and final?

后端 未结 11 1244
天涯浪人
天涯浪人 2020-11-27 08:51

I\'m always confused between static and final keywords in java.

How are they different ?

11条回答
  •  -上瘾入骨i
    2020-11-27 09:26

    final -

    1)When we apply "final" keyword to a variable,the value of that variable remains constant. (or) Once we declare a variable as final.the value of that variable cannot be changed.

    2)It is useful when a variable value does not change during the life time of a program

    static -

    1)when we apply "static" keyword to a variable ,it means it belongs to class.
    2)When we apply "static" keyword to a method,it means the method can be accessed without creating any instance of the class

提交回复
热议问题