I am working on a project on banking. I am using BlueJ as my IDE. Can I use more than one class in the source code.
package Bank;
public class Bank{
//some methods
//some code
}
class Main{//Calling this class from another .java file.
//some methods
public void getRandom()
{
return somenumber;
}
}
I cannot call class Main from another class.
Can anyone explain me why.
You cannot have two public classes in one file. Your code compiles because Main
is not public. But that means only the code in Bank
can see it. To call Main
from another class, create a file Main.java
for your Main
class and move the code into it.