Hi Rashmi,
Strange , but true i too tried out the same thing last night !!
I was surprised that even if my class ( say D.java) does not
have any public classes declared the code compiles and runs.
So i think it is not necessary to have a public class atleast
for running your file !!
Some points which i noticed :
1. As the current example does not have any "public" class
i can save the file by any name. But when i run ( java D ) ,
it gives the runtime error :
Exception in thread "main" java.lang.NoClassDefFoundError: D 2. Suppose if we declare ( say E ) as "public"
then the name of the file you save to should be E.java.
Otherwise you will get compile time error .
3. Also if E is declared as "public" we should not declare
any other class as public
Otherwise you will get compile time error .