+ 2
Can anyone pls tell me that why static is used in every method(function) in java?( while this is not the case in C++.)
what is difference if we remove static as it shows error in java.
2 odpowiedzi
+ 5
We don't use static in every method in Java.
Static means the member is bound to the class itself rather than an instance of the object.
To understand what that means you will need some practice with OOP first.
Anywho, basically when you are in a static method (which the main is) you cannot call a non-static method on command. This is because you have no object instance, your in something static. So if you call a non-static method from a static method like you normally would, you would get the error "non-static member cannot be references from a static context" or something worded similar to that.
+ 1
thank u very much!!!!