Bear Bibeault wrote:No it's not. It's calling the method for the instance of the object you put into obj (please try for better variable names). That gives it a non-static context. In your first example. you're just calling it withou any instance.
abalfazl hossein wrote:then main method is an exception, Right?
You can't call something that doesn't exist. Since you haven't created an object, the non-static method doesn't exist yet. A static method (by definition) always exists.
If you're already in a non-static method, you've already got a suitable object, which is the one represented by this. Calling show() is equivalent to calling this.show().
Matthew Brown wrote:
abalfazl hossein wrote:then main method is an exception, Right?
No, the main method is the same as any other static method.
abalfazl hossein wrote:
Matthew Brown wrote:
abalfazl hossein wrote:then main method is an exception, Right?
No, the main method is the same as any other static method.
If it isn't, Then give me an example that a static method can use non static method. That static method in this case is not main.Thanks in advance
abalfazl hossein wrote:If it isn't, Then give me an example that a static method can use non static method. That static method in this case is not main.Thanks in advance
Consider Paul's rocket mass heater. |