- 1

How to call static member functions?

static member called direct no need to create object

27th Sep 2017, 8:25 PM
Nishu Dwivedi
Nishu Dwivedi - avatar
9 ответов
+ 3
you answered your own question 😋 static void msg(){System.out.println("hello");} main msg(); output hello
27th Sep 2017, 8:52 PM
D_Stark
D_Stark - avatar
+ 2
@Bagshot i found this You do need to create instances, because a random-number generator has state. Specifically, state that controls the current position in the pseudo-random sequence. If you want multiple independent generators (that don't share state), then you need separate instances.
27th Sep 2017, 9:18 PM
D_Stark
D_Stark - avatar
+ 1
@Bagshot i didnt know that, i have used Random a few times and have always created and instance maby becuase its part of package util?
27th Sep 2017, 9:06 PM
D_Stark
D_Stark - avatar
0
static member call directly
27th Sep 2017, 8:26 PM
Nishu Dwivedi
Nishu Dwivedi - avatar
0
What about Random? It's apparently static, yet every example I see uses an instance. Strange.
27th Sep 2017, 9:02 PM
Bagshot
Bagshot - avatar
0
@David, it confuses me as well. Can't find a decent explanation, either.
27th Sep 2017, 9:08 PM
Bagshot
Bagshot - avatar
0
because static member called automatically and once
28th Sep 2017, 2:01 AM
Nishu Dwivedi
Nishu Dwivedi - avatar
0
@David: thanks, mate, that kind of makes sense now. @Gordie: I'm doing a software development course and one of the questions asked me to select static classes from a list. The correct answers were Random and Math. It left me a little confused as I did not think Random was static, but apparently so.
28th Sep 2017, 6:36 AM
Bagshot
Bagshot - avatar