+ 1

What does"static" means in java language?

Ex. Public static void fun(){}

4th Mar 2019, 5:21 PM
reza
reza - avatar
5 Answers
+ 11
There is a big concept of static keyword in Java Static keyword is very useful in java if you creat your java veriable and method static it belongs to the class it mens if asses static member in main method So you do not need to create its object you simply asses class static method and veriable using class name here is syntax : ClassName.Method() or ClassName.Veriable here is sololearn explanation https://www.sololearn.com/learn/Java/2159/
4th Mar 2019, 6:03 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 1
Static functions cannot be overridden, while "normal" can.
4th Mar 2019, 5:44 PM
Théophile
Théophile - avatar
+ 1
A little example on a static variable, If you wanna count each time a name is added then you can use the static keyword https://code.sololearn.com/cZ0N8tScMtgw/#java
4th Mar 2019, 9:08 PM
JavaBobbo
JavaBobbo - avatar
+ 1
you can override static method (but only) with other static method class Test{ public static void main(String[] args) { var b = new ClassB(); b.doSomething(); } } class ClassA { static void doSomething() { System.out.println("in Class A"); } } class ClassB extends ClassA { static void doSomething() { System.out.println("in Class B"); } } //output: in Class B
5th Mar 2019, 12:42 AM
zemiak
+ 1
//another example. Static variable keeps the same value for all instances of class class Stat { static int num; } class Main { public static void main(String[] args) { Stat.num = 1; Stat.num++; //num=2 var A = new Stat(); A.num++; //num=3 var B = new Stat(); B.num++; //num=4 System.out.println(B.num); //output: 4 } }
26th Mar 2019, 4:53 PM
zemiak