Java Find Output Questions and Answers - Array

📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.

🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.

▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube

▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube

Here are 10 Java code snippets designed to test your understanding of Java Arrays. Each question includes a code snippet and multiple-choice options for the output. After you complete the test, you can check your score, the correct answer, and an explanation. These snippets cover basic operations with arrays, such as indexing, assignments, and properties like length and default initialization values

1. What will be the output of the following Java code?

int[] arr = {1, 2, 3, 4, 5};
System.out.println(arr[2]);
a) 1
b) 2
c) 3
d) 4

2. What will be the output of the following Java code?

int[] arr = new int[3];
System.out.println(arr[0]);
a) null
b) 0
c) 1
d) undefined

3. What will be the output of the following Java code?

int[] arr = {1, 2, 3};
System.out.println(arr[3]);
a) 3
b) Throws an exception
c) 0
d) undefined

4. What will be the output of the following Java code?

String[] languages = {"Java", "Python", "C++"};
System.out.println(languages.length);
a) 2
b) 3
c) 4
d) None of the above

5. What will be the output of the following Java code?

int[] numbers = {10, 20, 30, 40, 50};
numbers[2] = 60;
System.out.println(numbers[2]);
a) 30
b) 60
c) 20
d) 10

6. What will be the output of the following Java code?

int[] a = {1, 2, 3};
int[] b = a;
b[0] = 10;
System.out.println(a[0]);
a) 1
b) 10
c) 0
d) 2

7. What will be the output of the following Java code?

char[] arr = {'A', 'B', 'C'};
System.out.println(arr[1]);
a) A
b) B
c) C
d) None of the above

8. What will be the output of the following Java code?

int[] arr = {7, 8, 9};
System.out.println(arr[arr[1]]);
a) 7
b) 8
c) 9
d) Throws an exception

9. What will be the output of the following Java code?

double[] arr = {1.1, 2.2, 3.3};
arr[0] = arr[2];
System.out.println(arr[0]);
a) 1.1
b) 2.2
c) 3.3
d) None of the above

10. What will be the output of the following Java code?

boolean[] arr = new boolean[5];
System.out.println(arr[3]);
a) true
b) false
c) null
d) Throws an exception

Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare