Static in java. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Static in java.

After seeing so many example I can't understand static. Have any simple & easy reference or example? Please explain.

19th Apr 2018, 12:35 AM
ⓤⓝⓢⓜⓐⓡⓣ ⓑⓞⓨ
ⓤⓝⓢⓜⓐⓡⓣ ⓑⓞⓨ - avatar
2 Answers
+ 1
"In Java, a static member is a member of a class that isn’t associated with an instance of a class. Instead, the member belongs to the class itself. As a result, you can access the static member without first creating a class instance." http://www.dummies.com/programming/java/what-is-the-static-keyword-in-java/ Math.pow(4, 2) can be called without creating a Math object, because it's static. If that function wasn't static, you'd have to create a Math object first to call it.
19th Apr 2018, 12:41 AM
Emma
19th Apr 2018, 3:02 AM
Ipang