Cannot import custom made java class
ello
I wrote a java class say (Money.java) which compiled fine. When I was importing it to another class (Account.java), the folowing error message appears:
Account.java.1:'.' expected
import Money;(an errow pointing to ";")
I dont think the code is wrong, because when I cut and attach the Money class code to the front of the Account class it compiled successfully.... I am confused! I wrote the import command according to the text book as follows:
import Money;
public class Account
{............}
By the way, both the Money and Account classes are saved in the save folder... How come it wont let me import...
Looking forward for an early reply.
Thanks
When using Java, if you have Money.java & Account.java in the same folder, you don't need to explicitly import Money into Account. Account already knows about Money simply because they are in the same folder. So, if you remove the import Money; your code should compile just fine.
In earlier version of Java, the compiler allowed importing a class from the default package. (The default package means the source code has no "package" statement at the start.) Since JDK 1.4, this is no longer allowed. Your book may be based on an earlier version.
Also, technically it is not the fact that the .class files are in the same directory that eliminates the need for an import. It is the fact that the classes are in the same package, in this case the default package. You never need to use import when classes are in the same package.