GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes methods will execute? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "methods will execute?" Watch "methods will execute?" New topic
Author

methods will execute?

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1376
i have public class and one main method. If i don't call (non main) methods within the main(), whether (non main) methods will execute?
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228

In the above code main method calls a method print() ( instance method ) so print() will get executed. If there is no call to any instance methods in the main method then none of them will execute . Program will terminate after executing all statements in main().
[ March 02, 2005: Message edited by: Srinivasa Raghavan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Avinash Pandit
Greenhorn

Joined: Oct 27, 2003
Posts: 5
no. Those methods won't get executed unless and until they are called from main() method or that class static method.

This code will print
In static method
In main method


-Avinash
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1376
Is it possible to call non static methods within the static initializer?
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
No. If you are calling a Non-Static method from a Static method, you 'll get an error. Logically speaking Static method's are Class Methods, so on calling a non static method from a static means, non static method of which instance are we referring to ?
 
GeeCON Prague 2014
 
subject: methods will execute?