Missing method body, or declare abstract in Java

后端 未结 4 1624
有刺的猬
有刺的猬 2021-01-19 02:35

I\'m new to Java and tried to get things running on my computer.

A simple \"hello world program\" fails calling a method

class helloworld
{   
             


        
相关标签:
4条回答
  • 2021-01-19 02:56

    This line:

    public static void helloWorld();
    

    is your problem. Ending a function with a semicolon implies you want it to be abstract and not have a body. This is similar to how methods in interfaces are declared, or if they are marked abstract i.e. no body.

    0 讨论(0)
  • 2021-01-19 02:56

    In this code line:

    public static void helloWorld(); remove semicolon.

    Make it like this:

    public static void helloWorld()

    To avoid this mistake further on, do it like this:

    public static void helloWorld() {

    An opening curly brace in the same line would make error detection easier.

    0 讨论(0)
  • 2021-01-19 03:10

    Remove the semicolon on the end of this line: public static void helloWorld();

    0 讨论(0)
  • 2021-01-19 03:12

    first you focus on your error.. solution of error is (

    abstract class HelloWorld
    {
    public abstract void(String[] args);
    

    you shoud try this ;)

    0 讨论(0)
提交回复
热议问题