legal main method signature in java

前端 未结 8 1028
甜味超标
甜味超标 2020-12-01 21:44
class NewClass{
public static void main(String a){
    System.out.print(\"Hello\");
}
}

When I\'m trying to execute above code, then it shows an er

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-01 22:34

    You need exactly the String[] args parameter (it's an array).

    The reason is that you need to declare the main() method with a specified signature (and a method signature contains its name, number of its parameters and the types of the parameters).

    So if you create a function which a different parameter type (String vs. String array), it is not recognized.

提交回复
热议问题