Class in java
Is it necessary to save my source file in java with "class name.java". If not then what is the condition?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jan 9, 2014, 8:21 AM EST
It follows from this that a .java file can have at most one public class.
If a .java file contains no public class, then you can name it what you like.
However, there's a lot to be said for having only a single class (public or not) per file and always giving it the same name as the class.