0
public static everything in java
Hello World! I have a simple question but I can't understand the reason why it happens? So why I shouldn't create every variable and every method as public static to have access to them from everywhere?
2 Antworten
0
Because sometimes you only need the variable in a part of the code, and it is simpler, more readable to not make it static and public.
For example:
for (int i = 0; i < x; i++) {
a += i;
}
For this, the variable i is useless after the loop, so you don't have to make it public and static
0
So what if I make it public and static? Will it run slower or will take more memory?