2013-10-24 4 views
1
public void toonBoten() 
    { 
     for(Boot tweedeboot: boten) 
     { 
      Boot.toonBoot(); 
     } 
    } 

Boot 클래스에서 toonBoot 메서드를 호출하려고합니다. 이 작업은 ArrayList 클래스의 Boot 유형 (클래스와 동일)의 모든 tweedeboot에 대해 수행해야합니다. toonBoot는 몇 줄의 정보를 인쇄합니다 (기본적으로 여러 좌표가 있습니다).다른 클래스의 메서드에서 메서드 호출 시도 중

어떤 이유로 든 "정적이 아닌 메서드 toonBoot()를 정적 컨텍스트에서 참조 할 수 없습니다."라는 오류 메시지가 항상 나타납니다. 내가 뭘 잘못하고 있니? 감사합니다.

+0

현재 메서드를 어떻게 호출 했습니까? –

답변

4

instance에서 메소드를 호출해야합니다.

public void toonBoten() 
    { 
     for(Boot tweedeboot: boten) 
     { 
      tweedeboot.toonBoot(); 
     } 
    } 

경우

Boot.toonBoot(); //means toonBoot() is a static method in Boot class 

참조 : 당신이

1

을하고 무엇

Class name에서 메서드를 호출하면이 메서드가 static 메서드라는 것을 컴파일러에 알릴 수 있습니다. 즉 hello() 방법 서명이 같은임을 Boot.hello()를 호출한다 : 당신은 객체 참조에서

통화를 수행하거나이 경우 tweedeboot에서해야합니까

public static void hello() {} 

. 이 메소드는 static 메소드 또는 instance 메소드 중 하나임을 컴파일러에 알리고 인스턴스와 클래스를 점검합니다.

관련 문제