ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Does the class name and the file name of the java program be same ? If yes why ?

user-image
تم إضافة السؤال من قبل srivatsan murali
تاريخ النشر: 2016/03/15
Waheeb Al-Rafati
من قبل Waheeb Al-Rafati , Software Development Engineer , Lead Technologies Inc

No, unless your class is a public class

Naeema Rabia
من قبل Naeema Rabia , Clinical Informatics Support Specialist , Cleveland Clinic Abu Dhabi

NO, it is not mandatory to keep the filename same as the class name. However, it is advisable because suppose we have a program with more than1 class, in that case after compiling the Java source file, a number of .class files will be generated.In this condition you will not able to easily identify which class need to be interpreted by java interpreter and which class containing Entry point.

Suppose ClassA is the class name and this class has the main() method. In that case,

Filename should be ClassA.java

 

Steps of execution:

javac ClassA.java

java ClassA

 

muqaddar raza
من قبل muqaddar raza , Senior Software Engineer , i2cinc

 

No, Class name and file name of Java Program should not necessary to be same if class name doesn't have the public modifier.

If Class name has public modifier then Java file name must be same otherwise compiler error.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟