OA Exams
What will be the output of System.out.println(“5” + 5);?
Answer: B
Explanation: The expression evaluates to "55" due to string concatenation.
Which collection allows duplicate elements in Java?
Explanation: The List interface allows duplicate elements.
What is the result of Integer.valueOf(“100”)?
Answer: A
Explanation: The Integer.valueOf("100") method returns an Integer object representing the value 100.
How do you find the length of a string in Java?
Explanation: The length() method is used to find the length of a string.
What does the synchronized keyword do?
Correct Answer: b) It ensures data is unreadable without proper authorizationExplanation: Encryption secures data by converting it into a form that cannot be read without the correct decryption key.
Which of the following is used to handle a potential exception in Java?
Answer: D
Explanation: All the keywords try, catch, and throw are used in exception handling in Java.
How do you declare a two-dimensional array in Java?
Answer: C
Explanation: Both int[][] arr; and int arr[][]; are valid ways to declare a two-dimensional array.
What will be the output of the following code? System.out.println(3 * 5 + ” apples”);
Explanation: The expression evaluates to "15 apples" due to string concatenation.
Which of the following keywords is used to create an instance of a class?
Explanation: The new keyword is used to create an instance of a class.
How do you define an interface in Java?
nswer: D
Explanation: You can define an interface using either public interface MyInterface { } or interface MyInterface { }.
What is the main purpose of the finally block in exception handling?
Explanation: The finally block is used to execute code regardless of whether an exception was thrown or not.
Which collection type allows elements to be stored in key-value pairs?
Explanation: The Map interface allows elements to be stored in key-value pairs.
What is the default value of a boolean variable in Java?
Explanation: The default value of a boolean variable in Java is false.
Which of the following statements correctly creates an ArrayList?
Explanation: Both ArrayList<Object> list = new ArrayList<>(); and ArrayList<String> list = new ArrayList<String>(); correctly create ArrayLists.
What does the throw statement do in Java?
Explanation: The throw statement is used to pass an exception to the caller.
Which of the following is a valid way to comment in Java?
Explanation: All the options represent valid ways to comment in Java.
What is the result of 5 > 3 && 3 < 2?
Explanation: The expression evaluates to false since one of the conditions is not true.
What keyword is used to prevent a class from being subclassed?
Explanation: The final keyword is used to prevent a class from being subclassed.
What does Collections.sort(list); do?
Explanation: The Collections.sort(list); method sorts the list in ascending order.
What will happen if you attempt to divide by zero in Java?
Explanation: Attempting to divide by zero will throw an ArithmeticException.