Home  |   STIU  |   WOW  |   SCJP  |   SCDJWS   |   JEE FAQ  |   About US  |  

FAQ
  Java FAQ
  JSP FAQ
  Servlet FAQ
 

Advertisement

XyzWs Java FAQ:
Can a .java file contain more than one java classes?


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
Advertisement
Can a .java file contain more than one java classes?

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.

 


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

Support  | Feedback  | Help