Hi...
pl help me with these qns..these are from javaprepare.com
1.What would be the results of compiling and running the
following class. Select the one correct answer.
class
test {
public static void main() {
System.out.println("test");
}
}
A.The program does not compile as there is no main method
defined.
B.The program compiles and runs generating an output of "test"
C.The program compiles and runs but does not generate any
output.
D.The program compiles but does not run.
I thought the compiler must complain 'wrong number of arguments in main()' because main() takes an array of
String as argument..But that is not one of the options, and the answer is given D.
cud somebody explain this ?
2.Which of the following are valid declarations for the main
method. Select all correct answers.
A. public static void main(String args[]);
B. public static void main(String []args);
C. final static public void main (String args[]);
D. public static int main(String args[]);
E. public static abstract void main(String args[]);
My answers are A and B , The answers given are A,B and C.Could somebody explain this?
This seems to be quite vague to me.Cud someone explain the legal access modifiers of the main() method? And , I remember having read in an earlier post here that the modifier private in the main method will not give any error ,I am not clear how that is possible too..
Thanks in advance,
Vidya.