Explore topic-wise MCQs in Java Programming.

This section includes 155 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.

151.

What will be the output of the program? 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]; System.out.print(" args[2] = " + s2); } } and the command-line invocation is > java CommandArgs 1 2 3 4

A. args[2] = 2
B. args[2] = 3
C. args[2] = null
D. An exception is thrown at runtime.
Answer» E.
152.

public interface Foo { int k = 4; /* Line 3 */ } Which three piece of codes are equivalent to line 3? final int k = 4; public int k = 4; static int k = 4; abstract int k = 4; volatile int k = 4; protected int k = 4;

A. 1, 2 and 3
B. 2, 3 and 4
C. 3, 4 and 5
D. 4, 5 and 6
Answer» B. 2, 3 and 4
153.

What will be the output of the program? public class CommandArgsThree { public static void main(String [] args) { String [][] argCopy = new String[2][2]; int x; argCopy[0] = args; x = argCopy[0].length; for (int y = 0; y < x; y++) { System.out.print(" " + argCopy[0][y]); } } } and the command-line invocation is > java CommandArgsThree 1 2 3

A. 0 0
B. 1 2
C. 0 0 0
D. 1 2 3
Answer» E.
154.

Which three are legal array declarations? int [] myScores []; char [] myChars; int [6] myScores; Dog myDogs []; Dog myDogs [7];

A. 1, 2, 4
B. 2, 4, 5
C. 2, 3, 4
D. All are correct.
Answer» B. 2, 4, 5
155.

Which four options describe the correct default values for array elements of the types indicated? int -> 0 String -> "null" Dog -> null char -> '\u0000' float -> 0.0f boolean -> true

A. 1, 2, 3, 4
B. 1, 3, 4, 5
C. 2, 4, 5, 6
D. 3, 4, 5, 6
Answer» C. 2, 4, 5, 6