Question#1 Which Java loop checks its condition at the end of the loop, guaranteeing at least one execution? a) do-while loop ✅- Answer b) for loop c) for-each loop d) while loop Question#2 What is the main characteristic of a for-each loop in Java? a) It traverses data structures like arrays without updating the loop variable manually. ✅- Answer b) It requires initialization inside the loop. c) It always uses integer indices to traverse arrays. d) It only works with primitive data types. Question#3 When should a while loop be preferred over a for loop in Java? a) When the loop variable must be initialized within the loop. b) When traversing through an array by index. c) When the number of iterations is not known in advance. ✅- Answer d) When exactly three iterations are required. Question#4 What is the output of the Java code: for(int j = 1; j<=10; j++) { sum = sum + j; } system.out.println("The sum of first 10 natural numbers is " + sum);? a) The sum of first 10 natural numbers is 60 b) The sum of first 10 natural numbers is 55 ✅- Answer c) The sum of first 10 natural numbers is 50 d) The sum of first 10 natural numbers is 45 Question#5 Which statement is true about the syntax of a for loop in Java? a) It requires curly braces even for single statements. b) Increment must be handled separately after the loop body. c) Only the condition appears in the loop header. d) Initialization, condition, and increment/decrement are all in a single line. ✅- Answer Question#6 How does a break statement affect a loop in Java? a) It terminates the entire Java program. b) It restarts the current loop from the beginning. c) It skips the rest of the loop iteration and continues with the next one. d) It exits the current innermost loop or switch statement immediately. ✅- Answer Question#7 What does a continue statement do in a Java loop? a) It skips the current iteration and jumps to the next loop cycle. ✅- Answer b) It terminates the Java program instantly. c) It ends the loop and moves to the next statement after the loop. d) It pauses and resumes after user input. Question#8 Where can the break statement be used in Java? a) Only outside any loops b) Anywhere in the Java program c) Only inside method definitions d) Inside loops or switch statements only ✅- Answer Question#9 How is a single-dimensional array declared in Java? a) datatype arr{}; b) datatype[] arr; ✅- Answer c) datatype< arr >; d) datatype-arr; Question#10 What is the output of traversing the int array initialized as a[0]=10; a[1]=20; a[2]=70; a[3]=40; a[4]=50; in order? a) 10 20 40 50 70 b) 10 70 20 50 40 c) 10 20 70 40 50 ✅- Answer d) 20 10 70 40 50 Question#11 How is a two-dimensional (2D) array represented in Java? a) As a single list separated by semicolons. b) As an array of arrays, commonly using syntax like datatype[][] arrayRefVar. ✅- Answer c) As a collection of arraylists by default. d) Using only one subscript per array name. Question#12 What is a dynamic array in Java as described in the text? a) A regular array with automatic resizing by default. b) An ArrayList that can grow or shrink at runtime and is part of the collections framework. ✅- Answer c) A static integer array that can be changed. d) A HashMap with array storage style. Question#13 What happens when an object in Java is no longer referenced? a) It is immediately deleted from disk. b) It is stored in the stack for later reuse. c) It generates a compilation error. d) It becomes eligible for garbage collection. ✅- Answer Question#14 Which is NOT a way to make an object eligible for garbage collection in Java? a) Assigning the reference to another object. b) Nulling a reference variable. c) Calling the toString() method on the object. ✅- Answer d) Creating an anonymous object. Question#15 How are command line arguments accessed in a Java program? a) Directly from the Runtime class. b) Via a special args.getArguments() function. c) With the System.console() method. d) Through the 'args' array parameter in the main method. ✅- Answer Question#16 What is the data type of command line arguments in Java? a) They are handled as objects in an ArrayList. b) They are stored as a list of integers. c) They are stored as an array of strings. ✅- Answer d) They are passed as a single string separated by commas. Question#17 What is the output when running class CommandLineExample with the argument 'sonoo'? a) The argument was: sonoo b) Argument received: sonoo c) First arg: sonoo d) your first argument is: sonoo ✅- Answer Question#18 What is the length property of a Java array used for? a) To make the array dynamic in size. b) To determine the number of elements in the array. ✅- Answer c) To set the size of the array after creation. d) To clear all elements from the array. Question#19 What differentiates a do-while loop from a while loop in terms of condition checking? a) While loops always execute at least once, do-while may execute zero times. b) Only the while loop has a loop body. c) do-while cannot contain increment statements. d) do-while checks the condition after executing the loop body, whereas while checks before. ✅- Answer Question#20 What is the main advantage of using an ArrayList over a regular array in Java? a) ArrayList elements always remain fixed once set. b) ArrayList only stores primitive types, not objects. c) Regular arrays have more built-in functionalities than ArrayLists. d) ArrayList can dynamically change size at runtime and allows element insertion and removal. ✅- Answer