Java main – call another method

I have the following code:

public static void main(String args[])
{
start();
}

I received this error: non static method start() cannot be referenced from a static context

How can I do that?

Solution

Create an instance of the class and call the start method of the instance

Foo f = new Foo();
    f.start();

Alternatively, the make method starts static by declaring the method static

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>