| Author |
main() is the entry point
|
Arnb Sen
Ranch Hand
Joined: Feb 23, 2004
Posts: 145
|
|
Hi All, I am a bit confused here. main() is the entry point for all applications. main() is the static method. So as is expected a static method can call from within another static method or static variable. So my question is methods called from within the main() method must be static. Variables called must be static. So does it not mean that everything will have to be static ?
|
Regards,<br />Arnab
|
 |
Dave Salter
Ranch Hand
Joined: Jul 20, 2005
Posts: 292
|
|
Methods called from within main() do not have to be static if they belong to a class that you have instantiated within main(). So, you can instantiate classes within main() and call methods on them.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9956
|
|
often, one of the first things you'll see in Class A's main method is a creation of an object of type A... i.e. within main you'll see A myA = new A(); now you can call A's non-static methods within main, on a myA.nonStaticMethod1(); myA.nonstaticMethod2(); etc.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
I think a simple example here is worth 1000 words.
|
 |
Arnb Sen
Ranch Hand
Joined: Feb 23, 2004
Posts: 145
|
|
oh ok.. Thanks
|
 |
 |
|
|
subject: main() is the entry point
|
|
|