0

why we use static in main and String[] args as arugment of main

public static void main (String[] args)

can u explain me following

static member functions should not refer to objects of that class. But we can access static functions through classname itself

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Mitja Bonca
0

Ok, The Main method must be static because it needs to exist without first being instantiated.

Static member functions shouldn't use objects in a class that need to be instantiated because they may or may not exist yet when the static function is called.

"but we can access static functions through the classname itself"
I assume would refer to that calling a static function you use the classname to reference the function, where as non static functions you would use the instance name to reference the function.

0

Here you can find some interesting answers on your question:
and here.
Have a good reading, and take is slow... you have to understand what these keyWords mean. Its something basic for the start.

Mitja

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.