Is the file name must be sam eas class name ?
Actually why in java it is like a rule because
Suppose there is a class(default modifier)

class Demo{
public static void main(String[] args){
System.out.println("hi bhabani");
But you saved it as a file name
Then you compile javac
What happens after that the code is succesfully compiled but open the folder where is saved see there is another file Demo.class
So as usually when you try to run that Hello file(java Hello) but there is no hello.class file. So there is Exception.
but if you try to run java Demo then you will get the out put.

If there is a public class in the program then you must give the same name as the public class name. otherwise it is compilation error.


If there are 10 classes/interfaces in a single java program then after compilation it will generate 10 class files(name as given in your program).

No comments:

Post a Comment