This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

main class file  RSS feed

 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference of writing public or not writing public for the main class ?
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
}
}

OR

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
}
}

What will be the differences in these codes ?
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello arnab, welcome to the ranch.
using the public keyowrd for a class makes that class visible to every other class in any other package. if you use the public keyword there can only be one public class in one file so this is allowed; saved as A1.java

while not using the public keyword makes it only visible to classes in the same package (this is what's known as default access)
davy
[ February 23, 2004: Message edited by: Davy Kelly ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!