Reputation: 33213
Ok.. A very noob question.
This is my first attempt to write a class in java.
I created a project (Bank), a package (bank), and two classes Account
, and Driver
So, my project looks like:
Bank --> src-->bank --> Account.java --> Driver.java
Now Driver.java
has main
.
How do i call Account.java
class from Driver.java
I have included package bank
on both the files.
Account myAccount = **Account**("foobar",12345); bold is where the error is.
It is not being able to find Account class.
Thanks
Upvotes: 1
Views: 295
Reputation: 9331
In Java you create objects by using the keyword new
Account myAccount = new Account("foobar",12345);
As a sidenote:
If all your classes are in the same package you don't need to import them, but if you had Account
in another package then you would have to import it by using
import path.to.package.Account;
Another sidenote as you continue to learn, not really related to this question:
If you were only to call a static method
in Account.java
, you wouldn't need to create an object. You would go like:
Account.mymethod()
Upvotes: 13