OA Exams
Which of the following methods can be used to convert a string to an integer?
Answer: B
Explanation: The correct method to convert a string to an integer is Integer.parseInt(String).
Which method is called when an object is created from a class?
Explanation: The constructor method is called when an object is created from a class.
How can you check if a string is empty in Java?
Answer: C
Explanation: You can check if a string is empty using either str.isEmpty(); or str.length() == 0;.
What is the purpose of the super keyword?
Answer: D
Explanation: The super keyword is used to call the parent class constructor and access parent class methods.
Which method can be used to remove an element from an ArrayList?
Explanation: The remove() method can be used to remove an element from an ArrayList.
What will the output be for System.out.println(1 + 2 + “3”);?
Explanation: The expression evaluates to "33" due to string concatenation.
How do you access the first element of an array in Java?
Explanation: The first element of an array is accessed using array[0].
What type of loop will always execute at least once?
Explanation: A do-while loop always executes at least once because the condition is checked after the loop body.
Which of the following will create an instance of a class named Car?
Explanation: Car myCar = new Car(); creates a new instance of the Car class.
What will the following code output? System.out.println(0.1 + 0.2 == 0.3);?
Explanation: Due to floating-point precision issues, 0.1 + 0.2 does not exactly equal 0.3, so it evaluates to false.