Question#1 Which of the following describes a local variable in Java? a) A variable declared within a method and accessible only there ✅- Answer b) A variable declared outside all methods, visible everywhere c) A variable declared with the static keyword inside a method d) A variable declared within a class and shared by all instances Question#2 How are instance variables initialized if not explicitly assigned in Java? a) They are initialized to zero only b) They are initialized with default values ✅- Answer c) They must be initialized in the constructor d) They remain uninitialized until used Question#3 What keyword is used to declare a class (static) variable in Java? a) final b) instance c) static ✅- Answer d) class Question#4 Which statement about implicit casting in Java is correct? a) It only works for reference types b) It happens automatically when assigning a smaller type to a larger type ✅- Answer c) It requires explicit syntax from the programmer d) It never happens between numeric types Question#5 What is explicit casting in Java also known as? a) Auto conversion b) Narrowing typecasting ✅- Answer c) Widening typecasting d) Type wrapping Question#6 What does the Integer.parseInt method do in Java? a) Converts a String to a double b) Converts a String to an int ✅- Answer c) Converts an int to a String d) Converts a double to an int Question#7 Which method is used to convert an int to a String in Java? a) valueOfInt() b) toString() c) String.valueOf() ✅- Answer d) parseInt() Question#8 What is a wrapper class in Java? a) A class that stores arrays b) A class for string manipulation c) A class to wrap control statements d) A class used to treat primitive types as objects ✅- Answer Question#9 Which of the following is the wrapper class for the primitive type 'int'? a) IntWrapper b) IntObject c) Integer ✅- Answer d) IntClass Question#10 What is autoboxing in Java? a) Automatic conversion of a primitive type to its wrapper class ✅- Answer b) Converting a class variable to an instance variable c) Manual conversion of a wrapper type to primitive d) Explicit casting from double to int Question#11 What describes unboxing in Java? a) Array to object conversion b) Narrowing typecasting c) Automatic conversion of a wrapper type to its primitive type ✅- Answer d) Manual conversion of a primitive to wrapper Question#12 Which control statement evaluates a Boolean expression and executes code if the condition is true? a) if statement ✅- Answer b) switch statement c) for loop d) continue statement Question#13 Which type of 'if' statement creates a chain of decisions in Java? a) for-each statement b) simple if statement c) switch-case statement d) if-else-if ladder ✅- Answer Question#14 In a switch statement, when is the default block executed? a) When the break statement is missing b) When no case matches the switch expression ✅- Answer c) When switch variable is a String d) When all case conditions are true Question#15 Which data type can be used as a case variable in a Java switch statement (since Java 7)? a) float b) String ✅- Answer c) boolean d) double Question#16 What is the main purpose of control flow statements in Java? a) To manage the execution order of program statements ✅- Answer b) To declare and initialize variables c) To create new objects d) To write comments in code Question#17 Which of the following best describes the for-each loop in Java? a) A loop that repeats a fixed number of times b) A loop for infinite execution c) A loop for traversing elements in an array or collection ✅- Answer d) A loop for switching between cases Question#18 Why are wrapper classes commonly used in Java? a) To use primitive data types where objects are required ✅- Answer b) To create local variables c) To convert objects to arrays d) To improve performance of arithmetic operations Question#19 Which output will be produced by the 'if' statement sample where x=10 and y=12 and code checks if (x+y > 20)? a) x + y is less than 10 b) x + y is greater than 20 ✅- Answer c) x + y equals 22 d) x + y is not defined Question#20 What happens if a break statement is omitted in a switch-case in Java? a) The default case runs automatically b) The switch block exits immediately c) Control falls through to the next case ✅- Answer d) An error occurs