if there are two class in a .java file ,one class is declared public why the other can't declared protected or private (the compiler complain that :there is no declaration)
I agree with Nitin Access modifers are private , protected , public and default. You don't type default only class test{}. A class can only be marked as public or default. Methods can be marked with private , protected , public and default. Inner classes can be marked private , public , default. I don't know if an innerclass can be marked protected. By i think you can. Anyone who can fill me in. // Snylt Master
>if there are two class in a .java file ,one class is declared public why the other can't Well, as Java is sometimes called C++ --, this is one of the rules meant to increase maintainability, productivity and reduce confusion, error prone constructs etc. Suppose you have two public classes in one java file. Now you quit the job and someone else tries to run one of the public classes whose name does not match the name of the java file and finds that there is a bug. He/She will surely have a trouble finding what file this class is defined in. Yes, this can also happen with non-public classes defined in one file and although it is not prohibited but it is definitly discouraged unless all the classes in that file are strongly related. HTH, Paul.