This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes main class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main class file " Watch "main class file " New topic
Author

main class file

Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
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 ?


Regards,<br />Arnab
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
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 ]

How simple does it have to be???
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: main class file
 
Similar Threads
intersting question
how many objects created
string problem
Quest About Constructors??
Thinking in Java problem