What is the output? int[] a = {1, 2, 3, 4, 5}; System.out.println(a[a.length - 1]);

Java Array Questions

Quiz
•
Computers
•
University
•
Easy
Satish T
Used 4+ times
FREE Resource
50 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
1
4
5 (Correct)
Compilation error
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will happen? int[][] m = new int[2][2]; System.out.println(m[1][1]);
0 (Correct)
Compilation error
NullPointerException
ArrayIndexOutOfBoundsException
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will be printed? int[] a = {5, 4, 3}; System.out.println(a[-1]);
5
-1
ArrayIndexOutOfBoundsException (Correct)
Compilation error
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Identify the result of the following snippet: int[][] arr = new int[2]; arr[0] = new int[2]; arr[1] = new int[3]; System.out.println(arr[1].length);
2
3 (Correct)
1
Compilation error
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which is valid declaration?
int arr[] = new int[3]; (Correct)
int[3] arr = new int[];
int[] arr = new int[];
int arr = new int[3];
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output? int[] a = {1, 2, 3, 4, 5}; System.out.println(a[a.length - 1]);
1
4
5 (Correct)
Compilation error
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output? int[] x = new int[]{1, 2, 3}; x = new int[]{4, 5}; System.out.println(x[1]);
1
2
5 (Correct)
Compilation error
Create a free account and access millions of resources
Similar Resources on Wayground
47 questions
PPS TEST 4

Quiz
•
University
50 questions
C++ Arrays Quiz

Quiz
•
University
48 questions
Java Quiz_1

Quiz
•
University
51 questions
C Programming Quiz

Quiz
•
University
45 questions
Java Programming Quiz

Quiz
•
University
50 questions
Orientation Quiz

Quiz
•
University - Professi...
50 questions
PF201: SCCPF2012223

Quiz
•
University
50 questions
Quiz

Quiz
•
University
Popular Resources on Wayground
25 questions
Equations of Circles

Quiz
•
10th - 11th Grade
30 questions
Week 5 Memory Builder 1 (Multiplication and Division Facts)

Quiz
•
9th Grade
33 questions
Unit 3 Summative - Summer School: Immune System

Quiz
•
10th Grade
10 questions
Writing and Identifying Ratios Practice

Quiz
•
5th - 6th Grade
36 questions
Prime and Composite Numbers

Quiz
•
5th Grade
14 questions
Exterior and Interior angles of Polygons

Quiz
•
8th Grade
37 questions
Camp Re-cap Week 1 (no regression)

Quiz
•
9th - 12th Grade
46 questions
Biology Semester 1 Review

Quiz
•
10th Grade