RSS Feed for JAVA Interview QuestionsCategory: JAVA Interview Questions

What is the first argument of the String array in main method? »

The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name.

What if I do not provide the String array as the argument to the method? »

Program compiles but throws a runtime error “NoSuchMethodError”.

What if I write static public void instead of public static void? »

Program compiles and runs properly.

What if the static modifier is removed from the signature of the main method? »

Program compiles. But at runtime throws an error “NoSuchMethodError”.

What if the main method is declared as private? »

The program compiles properly but at runtime it will give “Main method not public.” message.

What is a compilation unit? »

A compilation unit is a Java source code file.

What is the purpose of garbage collection? »

The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources may be reclaimed and reused.

How are this and super used? »

this is used to refer to the current object instance. super is used to refer to the variables and methods of the superclass of the current object instance.