Hi!
There are a few things which i think I shd share with u first so that i am able to convince u.
1) The mofdifier.The modifier here is defaulty ansd not public.
2) Classs level whether top level or anyother..
If the modifier is public and class is top level its a necessary condition that for compiling that
a) Source Name shd be same as class name
For efficient running(no run time error_)
a) Main method shd b perfect.
Now the case of yr example..
Your class has no access modifir => it translates to friendly or default access.
Hence the condition for efficient compiling in this case is that
1) source file != name of class file.
they can be different.. and yet compile.
For running the condition ois :
That main method shd be correct..
Feel free to touchbase if any query.
I am attching a program that i have done today itself...
//top level class with default access modifier.Class compiles.It will not compile only when main method is not perfect
class abc /* this class will compile even if the file name is different from source file name*/
//class firstdefault//I saved the file earlier as firstdefault.java/.Then changed the name to a different source name.Still it compiled...
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
/* So conclusion...if a class file is having default access modifier , we can compile the class successfully
a) Even if source name different...from class name.
Runs successfully
a)only if main is absolutely correct.
Plz revert in case of doubt or anything wrong abt my code...
at
atin_sehgal@hotmail.com
Originally posted by bhakti soman:
hi
i have compiled this code
class bhatki
{
public static void main(String arg[])
{
}
}
saved it as demo.java works fine with me.
that means you need not save file same as that class which contains main mehod.
please help me if i am wrong.