Search code examples
javaclassbluej

Two classes in one class in Blue J


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.


Solution

  • 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.