+ 2

What is the difference between private static void Main() and public static void Main() in c# and JAVA?

what is the difference about using private or public in Main method in c# and JAVA?

1st Jun 2018, 7:03 AM
Nurman Tajir
Nurman Tajir - avatar
2 Answers
+ 4
First it's important to know that the "main" method is used as an entry point for the application, this is why it must be accessible with the access modifier "public" in it's signature. In Java the "main" method used as entry point must be "public static void main(String []) args{}", but if you create a perfectly fine "private static void main(){}" method, the compiler should not complain at all (at least in Java), but just know that the compiler will think of that private main method as an overwritten version of "main", and it will not be used as the entry point of your application. Hope this helped you understand better Norman.
1st Jun 2018, 1:32 PM
Roberto Guisarre
Roberto Guisarre - avatar
+ 3
thank you
1st Jun 2018, 10:04 PM
Nurman Tajir
Nurman Tajir - avatar