| Author |
public static void main()
|
Nilanjan Sahu
Greenhorn
Joined: Apr 27, 2008
Posts: 3
|
|
|
i read in many reputed books and also seen that a static function cal call only static members but in java public static void main() can call all functions. How?
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 10040
|
|
a static method can only access static members... or constructors. Once you construct the object, you can call it's non-static methods. a common idiom you'll see is public class SomeClass { public static void main(String args[]) { SomeClass myInstance = new SomeClass(); myInstanct.callAMethod(); } public void callAMethod(){ //do something } }
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
 |
|
|
subject: public static void main()
|
|
|