+ 3

What is the use of static

27th Jan 2017, 7:03 AM
Sambit sinha
2 Réponses
+ 6
Java static keyword The static keyword in java is used for memory management mainly. We can apply java static keyword with variables, methods, blocks and nested class. The static keyword belongs to the class than instance of the class. The static can be: variable (also known as class variable) method (also known as class method) block nested class 1) Java static variable If you declare any variable as static, it is known static variable. The static variable can be used to refer the common property of all objects (that is not unique for each object) e.g. company name of employees,college name of students etc. The static variable gets memory only once in class area at the time of class loading. 2) Java static method If you apply static keyword with any method, it is known as static method. A static method belongs to the class rather than object of a class. A static method can be invoked without the need for creating an instance of a class. static method can access static data member and can change the value of it.
27th Jan 2017, 10:43 AM
Faruque Hossain
Faruque Hossain  - avatar
+ 4
In Java Variables can be declared with the “static” keyword. Example: static int y = 0; When a variable is declared with the keyword static, its called a class variable. All instances share the same copy of the variable. A class variable can be accessed directly with the class, without the need to create a instance. I think this is useful for you or check this website http://crunchify.com/java-static-methods-variables-static-block-and-class-with-example/
27th Jan 2017, 7:10 AM
ADITYA AVADHANI M.L
ADITYA AVADHANI M.L - avatar