Aniket S. Kulkarni wrote:
I want to say, you cannot mark more than one class as public inside one java file. Yes of course you can place Movie class in Movie.java file, but in same file you can not mark it as public.
Don't misinterpret. Am I correct or not?
You're close.
You can't have two
top-level public classes in the same .class file. You can have a a top-level public class and one or more nested public classes though.
Also (although this is a really minor point), I think the spec allows multiple top-level public classes in the same
source file, just not in the same
class file. Compilers are free to enforce tighter restrictions though, and every one that I know of these days does prohibit multiple top-level public classes in the same .java file. (About 12-14 years ago, I think I used a compiler from IBM or someplace that didn't enforce that restriction on .java files.)