0

for example,

1.

public class Something {
     public static void main(String[] args){
        System.out.print("Hello World");

     }
}

2.

class Something {
      public static void main(String[] args) {
         System.out.print("Hello World");

      }     
}
Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
find_x
  • 157
  • 6

3 Answers3

0

These are different access modifiers: 1 is public and the lack if modifier in 2 indicates default access. For more information check:

https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

peter.petrov
  • 38,363
  • 16
  • 94
  • 159
0

This changes the access for this class. If you're using only one package, then it doesn't matter, but public allows this class to be visible outside the package, while no identifier does not allow this.

saagarjha
  • 2,221
  • 1
  • 20
  • 37
0

public, protected and private are access modifiers. Public means that the class may be accessed by any other class, protected means it can be accessed by any subclass, private by the class itself, no modifier (just class) means "package private", so the method may be accessed by classes from the same package.

Mingle Li
  • 1,322
  • 1
  • 15
  • 39