I have noticed that if don\'t write public
before a class its works same as like a public class
. I can\'t understand why so? It should show a error
It works the same only because you are working with just probably one file and in the same package.
If you have more than one package then you have the problem. The class that doesn't have "public" before the name of class cannot be created in another package. You cannot use its constructor. You just cannot access it outside of the package that the class was created in.
If you don't give an access modifier it's by default package private access. The class is not accessible outside of the package. Ideally the JLS should've included a keyword for package access to avoid confusion and unintended consequences.
Something like,
default class Student{}