0

What does static mean?

7th Feb 2017, 6:36 AM
Ashish Wayne
Ashish Wayne - avatar
3 Respostas
+ 2
In Java static is a keyword which can be used with functions or class and variables. Functions of a static class and static functions can be invoked without creating objects. Lifetime of a static function is entire program, A static function will not release memory until program finishes. This is the reason why main function is static
7th Feb 2017, 6:44 AM
Ravindra Sisodia
Ravindra Sisodia - avatar
+ 1
For a variable within a Java class that uses the keyword static, this means that all instances of that class will share the same value of that variable. class myClass { private static int count; myClass() { count++; } int getCount() { return count; } } Here each time a new instance of the class myClass is instantiated the count variable is incremented by 1. Anytime an instance accesses the getCount() method that same value is returned no matter which instance calls it as they all share the same variable.
7th Feb 2017, 6:45 AM
ChaoticDawg
ChaoticDawg - avatar
0
static is a keyword in Java. It is used to create a single copy of the variable in the entire program. The static variables are created only once and each object of the class uses the same variable. If the variable is not declared static then a new copy of the variable is created for every single object of the class. Methods can also be static.
7th Feb 2017, 6:49 AM
Varun Moghe
Varun Moghe - avatar