나는 무엇인가를 이해하려고 노력하고 있습니다. testClass (z1) 객체의 요점은 무엇입니까?testClass 객체를 만드는 이유
내가 이해하는 방식은 모든 다른 개체의 출발점입니다. 나는 이것이 무엇을 의미하는지 정말로 묻고 있는데, 왜/어떻게 testClass가 자신의 인스턴스를 필요로 하는가? 동일한 결과를 얻을 수있는 또 다른 방법이 있습니까? 다음은
코드 : - 어떤 도움
이public class testBank {
creditAccount a1 = new creditAccount("Mary Chapple", 2400.41);
creditAccount a2 = new creditAccount("Jim Smith", 2.56);
creditAccount a3 = new creditAccount("Henry A Jones", 700.89);
currentAccount b1 = new currentAccount("Simon Hopkins", 86.01);
currentAccount b2 = new currentAccount("Jack C Whitheridge", 40000.29);
currentAccount b3 = new currentAccount("Bill Sutton", 100.23);
depositAccount c1 = new depositAccount("Theo Gibson", 145.99);
depositAccount c2 = new depositAccount("Jasper Williams", 3000.29);
depositAccount c3 = new depositAccount("Julie Banks", 1000001.99);
savingsAccount d1 = new savingsAccount("Burnard White", 2400.42);
savingsAccount d2 = new savingsAccount("Richard Bennett", 203.16);
savingsAccount d3 = new savingsAccount("Bob Robinson", 10000.11);
public testBank()
//Create an array of objects.//
{
bankAccount[]theAccounts = {a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3};
showAccounts (theAccounts);
}
private void showAccounts(bankAccount[] aa)
{
for (int i = 0;i <aa.length;i++)
{
System.out.println("Account Holder: " +aa[i].getAccountName());
System.out.println("Balance = £" +aa[i].getBalance());
System.out.println("Balance pluss APR = £" +aa[i].calculateInterest());
}
}
public static void main(String[]args)
{
testBank z1 = new testBank();
}
감사합니다.
다른 모든 개체는 testClass 개체에서 시작합니까? 나는 당신의 질문을 정말로 이해하지 못합니다. – Keppil
여기에 묻는 일반적인 질문에 따라, 내 대답은 인스턴스 메서드를 호출하는 인스턴스가 필요하다는 것입니다. 그렇지 않으면'main' 메쏘드에서'static' 메쏘드 만 호출 할 수 있습니다. – jlordo
최근에 나는 superClass, 다양한 subClasses (A, B, C)와 testClass를 설정했다. testClass에서 여러 가지 subclass 객체를 만들었다. AClass a1 = new ACLass – user2292173