T
T
Tagoryanin2021-08-27 12:39:57
Java
Tagoryanin, 2021-08-27 12:39:57

Why doesn't calling the main method from another class work?

Code like this:

public class BankAccount {

    int id;
    String name;
    double balance;

}

class BankAccountTest {
    public static void main(String[] args) {

        BankAccount MyAccount = new BankAccount();
        BankAccount YouAccount = new BankAccount();
        BankAccount HisAccount = new BankAccount();

        MyAccount.id = 1;
        MyAccount.name = "ZY";
        MyAccount.balance = 12.35;

        YouAccount.id = 2;
        YouAccount.name = "BL";
        YouAccount.balance = 3654.55;

        HisAccount.id = 3;
        HisAccount.name = "VL";
        HisAccount.balance = 1662.35;

        System.out.println(YouAccount.balance);
    }
}


Throws:
Error: Main method not found in class BankAccount, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tagoryanin, 2021-08-27
@Tagoryanin

In IntellijIDEA, when moving the main method from the main class, you must change the launch configuration to designate the new class as the main class.
6128c02e69f3d336833496.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question