+ 1

what is the meaning and use of 'static'

when defining a method we use public or static so what is the correct meaning of using it there

19th Jan 2017, 3:23 PM
Vishal Dubey
Vishal Dubey - avatar
3 ответов
+ 2
It makes the variable/function part of the class, not an object. This means you don't need a new object to access them, and every object of that class shares the very same functions and variables, not there own versions of them. Example: You have a static function 'static int fac(int a);' in a class called 'Math'. Now you can call it in other classes using Math.fac(a); instead of needing an object Math math = new Math(); and calling math.fac(a); This can also be used to call functions directly in the main function.
19th Jan 2017, 3:34 PM
Robobrine
Robobrine - avatar
+ 1
public mean your method can be accesible outside the class. static mean you dont need to instatiate the class to call the method
19th Jan 2017, 3:33 PM
Gusti Arya
Gusti Arya - avatar
+ 1
static method or atribute no need to access with a object. You access them directly with class name.
19th Jan 2017, 5:37 PM
Faruque Hossain
Faruque Hossain  - avatar