X
Xiaoshen Li
Dear All,
I am confused with the class name and the file name in JAVA. For
example, I have a file called "Test.java". The content of file is:
public class Money
{
//definitions of the class//
}
public class Driver //a driver program to test Money class
{
public static void main(String[] args)
{
Money aMoney = new Money();
....
}
}
Now, when I compile the file "Test.java". Errors came out as following:
Test.java:6: class Money is public, should be declared in a file named
Money.java
public class Money
^
Test.java:67: class Driver is public, should be declared in a file named
Driver.java
public class Driver
I know my program will work if I put class Money alone in the file
Money.java, put class Driver alone in Driver.java and just compile
Driver.java. But I hope to find out why what I am doing is not working
and how I can make it work.
Thank you very much for your help.
I am confused with the class name and the file name in JAVA. For
example, I have a file called "Test.java". The content of file is:
public class Money
{
//definitions of the class//
}
public class Driver //a driver program to test Money class
{
public static void main(String[] args)
{
Money aMoney = new Money();
....
}
}
Now, when I compile the file "Test.java". Errors came out as following:
Test.java:6: class Money is public, should be declared in a file named
Money.java
public class Money
^
Test.java:67: class Driver is public, should be declared in a file named
Driver.java
public class Driver
I know my program will work if I put class Money alone in the file
Money.java, put class Driver alone in Driver.java and just compile
Driver.java. But I hope to find out why what I am doing is not working
and how I can make it work.
Thank you very much for your help.