简体   繁体   中英

How to call non-static method in another class's static method in java?

I have this method in one of my class

@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");

and i want to call this non static method in this static method (another class)

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
} 

any help ??

Pass instance of your class containing non-static methods into static method

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

or create instance in it:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM