• Post Reply Bookmark Topic Watch Topic
  • New Topic

calling main function explicitly?  RSS feed

 
Sachin Tripathi
Ranch Hand
Posts: 368
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As we all know that main function is called by jvm at the time of interpretation ...can we call main function explicitly?
 
Stephan van Hulst
Saloon Keeper
Posts: 7975
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not? It's a regular static method like any other.
 
Sachin Tripathi
Ranch Hand
Posts: 368
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you stephan ,but i was thinking as we have to pass a string array as its argument.do jvm too passes anything as argument while accessing main function
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin Tripathi wrote:do jvm too passes anything as argument while accessing main function


Try it. What does the JVM passes to the main method? ... when the application is called with different parameters.

Henry
 
Sachin Tripathi
Ranch Hand
Posts: 368
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you henry
so by calling main function explicitly we can execute 2 classes simultaneously?
 
Stephan van Hulst
Saloon Keeper
Posts: 7975
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. First of all, when you call a method, you don't start running two things at the same time, unless the method spawns a new thread (such as Thread.start() or ExecutorService.submit()). Secondly, you don't "execute classes". You invoke a method, and when it returns you're back where you were.
 
Sachin Tripathi
Ranch Hand
Posts: 368
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i just wanted to say that when we execute a class demo1 ..when main method is called the content of demo class is also executed
Screenshot-(17).png
[Thumbnail for Screenshot-(17).png]
example of what i m trying to say
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not at all. You have explicitly invoked code in a different class. You can do that from any method. As long as the code called in actually accessible.

And please always copy and paste code not pictures.
 
Sachin Tripathi
Ranch Hand
Posts: 368
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok ..understood..thank you all for the help
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!