+ 2

What did static do in program? Is static is compulsory or nt?

11th Jan 2018, 3:03 PM
Harsh Agrawal
Harsh Agrawal - avatar
5 odpowiedzi
+ 2
static means that a methos or field belongs to the whole class, that means it is not invoked on an instance static methods are invoked ClassName.method() non-static: variable.method() main must be static, all fields and methods you access directly (not through obj.something) from static method must be static for example when you have ArrayList's method size(), it is not static because every concrete ArrayList has its own size Double.parseDouble() is static, because the whole class Double provides one way to convert String to double
11th Jan 2018, 3:11 PM
michal
+ 3
before starting working with objects, every your method is static main is always static
11th Jan 2018, 3:34 PM
michal
+ 1
can u explain me in simple language??
11th Jan 2018, 3:18 PM
Harsh Agrawal
Harsh Agrawal - avatar
+ 1
In simple language, I think that it can be resumed like this: if you are not using objects, put static. if you are, dont put it.
15th Feb 2018, 7:07 PM
Paul
Paul - avatar