+ 1

What is the significance of static keyword in Java??

10th Aug 2018, 8:37 AM
Tensa
Tensa - avatar
3 Réponses
0
https://www.sololearn.com/learn/Java/2159/ if you just started learning JAVA, be patient, you will get there. 😀
10th Aug 2018, 8:52 AM
Itoroabasi Unang
Itoroabasi Unang - avatar
0
Tensa basically it means that it pertains to the class as well as the objects created, so if you had two methods public class Example{ private int A = 0; private static int PI = 3.14 public static void exMethod1(){} public void exMethod2(){} } you would invoke exMethod1 using the class name, an object of the Example class can also use a static method or variable, ex: public class Program{ public static void main(String[] args){ Example.exMethod1(); \*static method call*/ Example A = new Example(); A.exMethod1(); \\works A.exMethod2(); \\works Example.exMethod2();\\doesnt work } } so you can call the static method from an object or by using the class name itself, static is useful for when you want a variable to maintain its data between objects so where as every object would have its own "a" variable from above, every object created would share the same PI variable and if ypu change PI for one it changes it for all the objects.
10th Aug 2018, 11:39 AM
StealthyTaco
StealthyTaco - avatar
0
thanks a lot for solving my issue!!
11th Aug 2018, 2:23 AM
Tensa
Tensa - avatar