Question 9
class GRC1 {public static void main(
String[] args) {}} // 1
class GRC2 {protected static void main(String[] args) {}} // 2
class GRC3 {private static void main(String[] args) {}} // 3
What is the result of attempting to compile each of the three class declarations and invoke each main method from the command line?
a. Compile-time error at line 1.
b. Compile-time error at line 2.
c. Compile-time error at line 3.
d. An attempt to run GRC1 from the command line fails.
e. An attempt to run GRC2 from the command line fails.
f. An attempt to run GRC3 from the command line fails.
and the answer to this question is given as
e.An attempt to run GRC2 from the command line fails.
f.An attempt to run GRC3 from the command line fails.
but when i tried to compile and run this program with all the three class names. it compiled and run well with no output. please clear me which is the correct answer.
class GRC1 {public static void main(String[] args) {}} // 1
class GRC2 {protected static void main(String[] args)
{
System.out.println(args[0]);
}
} // 2
class GRC3 {private static void main(String[] args) {
System.out.println(args[0]);
}
} // 3
This code also worked well and pinted the string in the commandline argumed for each of class run