Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main class file

 
Arnb Sen
Ranch Hand
Posts: 145
  • 0
  • 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
  • 0
  • 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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic