dcsimg
why we use public in main function
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Shiva_kumaran
Posted On:   Tuesday, October 10, 2006 02:18 AM

why we use public in main function?
eg:
class test
{
public static void main(string args[])
{
system.out.println("hello world");
}
}

Re: why we use public in main function

Posted By:   Christopher_Koenigsberg  
Posted On:   Saturday, October 21, 2006 11:05 AM

I think (?) you can write a method called "main" with any modifier you want, but unless it matches the exact signature given, you won't be able to have it called automatically when you try and run your class as an application.

Re: why we use public in main function

Posted By:   Sarfaraz_Dilawar  
Posted On:   Wednesday, October 11, 2006 05:38 AM

Every function is called by sum function but in case of main. it is called by the compiler. if we didnt giv public modifier to main then compiler can not recognize the main method and a compile time error results...



Hope this will help u to clear ur concept
U can refer (Khalid Mogal Core Java book)

Re: why we use public in main function

Posted By:   Robert_Lybarger  
Posted On:   Tuesday, October 10, 2006 09:09 AM

If it wasn't public, how would you call main() to get started?
About | Sitemap | Contact