FAQ

Java

JSP

Servlet


Advertisement



Can a .java file contain more than one java classes (or interfaces)?

Yes, a .java file can contain more than one java classes (or interfaces). But there are two restrictions:

  • A .java source file can contain at most one top-level class (or interface) defined by the public modifier.
  • The .java file name must be the same as the public class' (or interface's) name.

Even an empty .java file is a valid source file too.


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend

Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |