2017-05-18 10 views
0

나는 내 수업자바의 다른 클래스의 정적 메서드에서 비 정적 메서드를 호출하는 방법은 무엇입니까?

@Override 
public void liveFlights(int one, int two, int three, int four, int five, 
         int six, int seven, int eight, int nine, int ten, int eleven, int twelve) { 
    System.out.println("There is "+counter+" flights at this moment "); 

    System.out.println("England to Netherland at 12.00 pm "+one+"is flight number"); 
    System.out.println("Netherland to England at 12.00 pm "+two+"is flight"); 
    System.out.println("Turkey to USA at 06.00 pm "+three+"is flight number"); 

중 하나에서이 방법이 있고 내가 (다른 클래스)

public static void searchResEntry() throws java.io.IOException // start of method 
{ 
    // variable declarations 
    String Name; 
    String Address; 
    Scanner read = new Scanner(System.in); 
    System.out.print("Please enter your following information for your reservation result: \n"); // displaying the information to enter for searching a reservation 

    System.out.print(" Enter Name : "); // displaying message to enter name 
    Name = read.nextLine(); // prompt for the name 
} 

도움이 정적 인 방법이 아닌 정적 메서드를 호출 할 ??

+0

을 - 정적 방법. – NAMS

답변

1
정적 메소드로의

public static void searchResEntry(YourClass instance) throws java.io.IOException // start of method 
    { 
     // variable declarations 
     instance.liveFlights(...); 

또는 인스턴스 생성 비 정적 메서드가 포함 된 클래스의

패스 예 : 정적 방법은 다음 비를 포함하는 클래스의 인스턴스를 필요로

public static void searchResEntry() throws java.io.IOException // start of method 
    { 
     // variable declarations 
     YourClass instance = new YourClass(); 
     instance.liveFlights(...); 
+0

내가 추가하는 것을 잊지, 비 정적 메서드는 내 추상 클래스에 그 인스턴스가 작동하지 않는 것 같아요. 그것은 달렸어? –

+0

추상 클래스를 인스턴스화 할 수 없으므로,이 추상 클래스를'extends '하는 클래스가 없으면 비 정적 (인스턴스) 메소드를 구현하는 것이 의미가 없습니다. 이 메소드를'abstract'로 선언하고 추상 클래스를 확장 한 클래스에서 구현을 제공하거나,이 메소드를'static'으로 선언하십시오 –