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」方法。
