Explore topic-wise InterviewSolutions in .

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

1.

Predict the output?// file name: Main.javapublic class Main {public static void main(String args[]) {int arr[] = {10, 20, 30, 40, 50};for(int i=0; i < arr.length; i++){System.out.print(" " + arr[i]);}}}(A) 10 20 30 40 50(B) Compiler Error(C) 10 20 30 40

Answer»
2.

class Test {public static void main(String args[]) {int arr[2];System.out.println(arr[0]);System.out.println(arr[1]);}}(A)00(B)garbage valuegarbage value(C) Compiler Error(D) Exception

Answer» None
3.

class Test {public static void main(String args[]) {int arr[] = new int[2];System.out.println(arr[0]);System.out.println(arr[1]);}}(A)00(B)garbage valuegarbage value(C) Compiler Error(D) Exception

Answer»
4.

public class Main {public static void main(String args[]) {int arr[][] = new int[4][];arr[0] = new int[1];arr[1] = new int[2];arr[2] = new int[3];arr[3] = new int[4];int i, j, k = 0;for (i = 0; i < 4; i++) {for (j = 0; j < i + 1; j++) {arr[i][j] = k;k++;}}for (i = 0; i < 4; i++) {for (j = 0; j < i + 1; j++) {System.out.print(" " + arr[i][j]);k++;}System.out.println();}}}(A) Compiler Error(B) 0 1 2 3 4 5 6 7 8 9 (C) 0 0 0 0 0 0 0 0 0 0 (D) 9 7 8 4 5 6 0 1 2 3

Answer»
5.

Which of the following is FALSE about arrays on Java(A) A java array is always an object(B) Length of array can be changed after creation of array(C) Arrays in Java are always allocated on heap

Answer»
6.

Output of following Java program?class Test{public static void main (String[] args){int arr1[] = {1, 2, 3};int arr2[] = {1, 2, 3};if (arr1 == arr2)System.out.println("Same");elseSystem.out.println("Not same");}}(A) Same(B) Not Same

Answer»
7.

Output of following Java program?import java.util.Arrays;class Test{public static void main (String[] args){int arr1[] = {1, 2, 3};int arr2[] = {1, 2, 3};if (Arrays.equals(arr1, arr2))System.out.println("Same");elseSystem.out.println("Not same");}}(A) Same(B) Not Same

Answer»
8.

class Test{public static void main (String[] args){int arr1[] = {1, 2, 3};int arr2[] = {1, 2, 3};if (arr1.equals(arr2))System.out.println("Same");elseSystem.out.println("Not same");}}(A) Same(B) Not same

Answer»