- 1
How to call static member functions?
static member called direct no need to create object
8 Réponses
+ 3
you answered your own question 😋
static void msg(){System.out.println("hello");}
main
msg();
output hello
+ 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.
+ 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?
0
static member call directly
0
What about Random? It's apparently static, yet every example I see uses an instance. Strange.
0
@David, it confuses me as well. Can't find a decent explanation, either.
0
because static member called automatically and once
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.