두 클래스, 하나는 Driver, 다른 하나는 BankAccount입니다. Driver에는 Driver라는 메소드가 있고 BankAccount에는 Deposit이라는 메소드가 있습니다. 내 드라이버 메서드에서 BankAccount.Deposit를 호출하려고 할 때 "정적이 아닌 메서드 Deposit()을 정적 컨텍스트에서 참조 할 수 없습니다"라는 오류가 나타납니다.다른 클래스에서 다른 클래스 및 메서드로 메서드 호출
이 코드를 실행하기 위해 내가해야 할 일에 대한 조언. 여기
import javax.swing.JOptionPane;
public class Driver
{
int choice;
String number;
//public Driver()
public Driver()
{
String number = JOptionPane.showInputDialog("1. Deposit 2. Withdraw 3. Balance 4. Change name 5. Exit");
int choice = Integer.parseInt(number);
do
{
if(choice == 1)
{
BankAccount.Deposit() = new Deposit();
Driver.Driver = new Driver();
}else if(choice == 2)
{
BankAccount.Withdrawl = new Withdrawl();
Driver.Driver = new Driver();
}else if(choice == 3)
{
BankAccount.getBalance = new getBalance();
JOptionPane.showDialog(balance);
Driver.Driver = new Driver();
}else if(choice == 4)
{
name = JOptionPane.showInputDialog(" Please enter a name");
Driver.Driver = new Driver();
}else if(choice ==5)
{
JOptionPane.showDialog("Goodbye" + name);
}
}while(choice >= 1 && choice <= 5);
}
}
는이 같은 코드를 작성한 이유를 이해하지 않습니다는 BankAccount 방법
import javax.swing.JOptionPane;
public class BankAccount
{
double balance = 400;
double deposit;
double withdraw;
double Interest = 1.05;
String name;
String accountNumber;
public BankAccount()
{
name = null;
accountNumber = null;
balance = 0;
}
public double Deposit()
{
String input = JOptionPane.showInputDialog("How much would you like to deposit?");
deposit = Integer.parseInt(input);
if (deposit < 10000)
{
balance = (deposit + balance);
}
return balance;
}
}
'새로운 예금()'? 'Deposit'은 _class_입니까? 어디서 어떻게 정의되어 있습니까? –
이 사이트에서 이미 여러 번 언급했듯이 - 입문용 자바 텍스트를 가져 오거나 다시 읽는 것을 고려해야합니다. 코드의 오류 수가 중요합니다. – Perception
비슷한 질문을 먼저 검색하십시오. 다음을보십시오 : http://stackoverflow.com/search?q=non-static+method+Deposit%28%29+cannot+be+referenced+from+a+static+context+[java] – RAS