好的..一个非常菜鸟的问题.
这是我第一次尝试用java编写一个类.
我创建了一个项目(Bank),一个包(bank)和两个类Account,以及Driver
所以,我的项目看起来像:
Bank --> src-->bank --> Account.java --> Driver.java
Run Code Online (Sandbox Code Playgroud)
现在Driver.java有了main.
我怎么称呼Account.java来自Driver.java
我bank在两个文件中都包含了包.
Account myAccount = **Account**("foobar",12345); bold is where the error is.
Run Code Online (Sandbox Code Playgroud)
它无法找到Account类.
谢谢
gtg*_*ola 13
在Java中,您可以使用关键字创建对象 new
Account myAccount = new Account("foobar",12345);
Run Code Online (Sandbox Code Playgroud)
作为旁注:如果你的所有类都在同一个包中,你不需要导入它们,但如果你有Account另一个包,那么你必须使用它来导入它
import path.to.package.Account;
Run Code Online (Sandbox Code Playgroud)
另一种旁注为你继续学习,没有真正涉及到这样一个问题:如果你仅仅调用static method中Account.java,你就不需要创建一个对象.你会喜欢:
Account.mymethod()
Run Code Online (Sandbox Code Playgroud)