News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

Java Interview Questions - More..

Started by sukishan, Jul 15, 2009, 01:41 PM

Previous topic - Next topic

sukishan

1. Q: What if the main method is declared as private?

    A: The program compiles properly but at runtime it will give "Main method not public." message.

2. 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". 
3. Q: What if I write static public void instead of public static void?

    A: Program compiles and runs properly. 

4. Q: What if I do not provide the String array as the argument to the method?

    A: Program compiles but throws a runtime error "NoSuchMethodError". 
 
5. Q: What is the first argument of the String array in main method?

    A: 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.
 

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

    A: It is empty. But not null.
   

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

    A: 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.
A good beginning makes a good ending

Quick Reply

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it has been approved by a moderator.

Name:
Email:
Verification:
Please leave this box empty:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

Shortcuts: ALT+S post or ALT+P preview