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.
Most Recent java Faqs
- How to avoid an java.util.ConcurrentModificationException with ArrayList?
- How to convert a given array to a list in Java?
- How to make Java objects eligible for garbage collection?
- What are local variables in Java?
- What are instance variables in Java?
- How many backslashes?
- What are class variables in Java?
Most Viewed java Faqs
- How to use HttpURLConnection POST data to web server?(24746)
- What is runtime polymorphism in Java?(18328)
- How to add BASIC Authentication into HttpURLConnection?(16088)
- What is String literal pool?(14754)
- Can the run() method be called directly to start a thread?(13991)
- What does Class.forname method do?(10593)
- Can transient variables be declared as 'final' or 'static'?(10446)