I am starting to learn Java and creating my first global hello function in Eclipse. I noticed that the following two functions, like in the default package in the src folder in my java project, seem to do the same:
class HelloWorld {
public static void main(String[] args){
System.out.println("Hello World!");
}
}
and
public class HelloWorld {
public static void main(String[] args){
System.out.println("Hello World!");
}
}
Both successfully print "Hello World!" to the console.
I read a little about the different types of classes, but I'm not sure which type of class I will declare with the first function. What is the difference between these two functions? Is java for my greeting a world class in the first case public?
source
share