Welcome Guest | Sign in | Register
Language Fundamentals - Discussion Page For Q.3001 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Language Fundamentals > Questions and Answers

Q: What will be the output of the program?
public class X
{
public static void main(String [] args)
{
String names [] = new String[5];
for (int x=0; x < args.length; x++)
names[x] = args[x];
System.out.println(names[2]);
}
}
and the command line invocation is
> java X a b
A. names B. null
C. Compilation fails D. An exception is thrown at runtime

Answer and Explanation

Answer:null

Explanation:
The names array is initialized with five null elements. Then elements 0 and 1 are assigned the String values "a" and "b" respectively (the command-line arguments passed to main). Elements of names array 2, 3, and 4 remain unassigned, so they have a value of null.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.