Language Fundamentals Questions
Practice Language Fundamentals MCQs with answers and explanations. Page 2 of 2.
Category
Java Programming
Topic
Language Fundamentals
Page
2 / 2
Mode
Practice
Questions
Open any question to view the answer and explanation.
Java command-line arguments indexing: determine what prints and whether an exception occurs.
public class CommandArgs {
public static void main(String[] args) {
String s1 = args[1];
String s2 = args[2];
String s3 = args[3];
String s4 = args[4]; // potential out-of-bounds
System.out.print(" args[2] = " + s2);
}
}
// Invocation: > java CommandArgs 1 2 3 4
Open
View answer
Java (jagged 3D int array) — how many lines will be printed by the nested loops?
public class Test
{
public static void main(String [] args)
{
int[][][] x = new int[3][][];
int i, j;
x[0] = new int[4][];
x[1] = new int[2][];
x[2] = new int[5][];
for (i = 0; i < x.length; i++)
{
for (j = 0; j < x[i].length; j++)
{
x[i][j] = new int[i + j + 1];
System.out.println("size = " + x[i][j].length);
}
}
}
}
Count the total println calls produced by the inner loop.
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.