3:50 pm - Tuesday February 19, 2943

Basic Interview Question4

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

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

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

 

41.What if I write static public void instead of public static void?

Program compiles and runs properly.

 

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

Program compiles but throws a runtime error “NoSuchMethodError”.

 

43.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.

 

44.If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?

It is empty. But not null.

45.How can one prove that the array is not null but empty using one line of code?

Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.

 

46.What environment variables do I need to set on my machine in order to be able to run Java programs?

CLASSPATH and PATH are the two variables.

 

47.Can an application have multiple classes having main method?

Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.

48.Can I have multiple main methods in the same class?    

No the program fails to compile. The compiler says that the main method is already defined in the class.

 

Filed in: Z-A Interview Questions

No comments yet.

Leave a Reply