CORE JAVA INTERVIEW QUESTIONS AND ANSWERS
>> Wednesday, May 25, 2011
Q:What if the main method is declared as private?
A:The program compiles properly but at run time it will give "Main method not public." message.
Q:What if the static modifier is removed from the signature of the main method?
A:Program compiles. But at runtime throws an error "NoSuchMethodError".
Q:What if I write static public void instead of public static void?
A:Program compiles and runs properly.
Q:What environment variables do I need to set on my machine in order to be able to run Java programs?
A:CLASSPATH=JAVA_HOME and PATH=location of jdl upto bin floder are the two variables.
Q:Can I have multiple main methods in the same class?
A:No the program fails to compile. The compiler says that the main method is already defined in the class.
A:The program compiles properly but at run time it will give "Main method not public." message.
Q:What if the static modifier is removed from the signature of the main method?
A:Program compiles. But at runtime throws an error "NoSuchMethodError".
Q:What if I write static public void instead of public static void?
A:Program compiles and runs properly.
Q:What environment variables do I need to set on my machine in order to be able to run Java programs?
A:CLASSPATH=JAVA_HOME and PATH=location of jdl upto bin floder are the two variables.
Q:Can I have multiple main methods in the same class?
A:No the program fails to compile. The compiler says that the main method is already defined in the class.
0 comments:
Post a Comment