I am not able to understand why this code doesn\'t compile:
class A {
public static void main(String[] args) {
System.out.println(\"hi\");
}
}
p
If you don't use the public keyword for the class it will be private by default (visible only within the file).
There can be only one public class per .java file, all the others need to be private. So class A can be public and class B doesn't need any modifiers in your example. The public class name must match the .java file name (eg. A.java can only contain one public class called "A").