public class App {
    // Insert code here
        System.out.print("Welcome to the world of Java");
    }
}

Which two code fragments, when inserted independently at line // Insert code here, enable the program to execute and print the welcome message on the screen?

A.

static public void main (String[] args) {
B.
static void main (String[] args) {
C.
public static void Main (String[] args) {
D.
public static void main (String[] args) {
E.
public void main (String[] args) {

题解

题目给的程序缺乏程序进入点─「main」静态方法。因此需要将其正确加入至程序中。

选项 A,使用 static 和 public 来修饰「main」方法,让它成为静态且公开的方法,这是正确的程序进入点的使用方式。

选项 B,没有使用 public 来修饰「main」方法,无法作为程序进入点。程序虽然可以编译,但会找不到可进入的「main」方法。

选项 C,作为程序进入点的「main」方法的名称只能是「main」,不能是「Main」,否则不会被当作程序进入点。

选项 D,正确,理由同选项 A。

选项 E,没有使用 static 来修饰「main」方法,无法作为程序进入点。程序虽然可以编译,但会找不到可进入的「main」方法。