DEV Community

Cover image for Difference between static and final in Java
Lalit Kumar
Lalit Kumar

Posted on

Difference between static and final in Java

Definition of Static

Static could be a keyword, applicable to the categories, variables, methods, and blocks. the category members, class, and blocks will be created static mistreatment “static” keyword ahead of the name of the category members, class, and blocks severally. once a category member is asserted as static, it becomes world for all alternative members of the category.
• A static variable acts sort of a world variable for all alternative knowledge members of the category.
• A static variable will be accessed before any object of the category exists.
• A static variable will be accessed with the category name within which it's outlined followed by the dot(.) operator.

Static strategies

• A static technique will solely decision alternative static strategies solely.
• A static technique will access static knowledge solely.
• A static technique can't be remarked “this” or “super” in any conditions.
• A static technique will be accessed with the category name within which it's outlined followed by the dot(.) operator.

Static category

• Java will have the idea of nested static category. The outer category can't be created static whereas the innermost category will be created static.
• A static nested category can't access the non-static member of the outer category.
• It will solely access the static members of the outer category.

Static Block

Static block is dead just once once the category is loaded. accustomed initialize the static variables of the category. Read more

Top comments (0)