OA Exams
What is the default value of a char variable in Java?
Answer: B
Explanation: The default value of a char variable is '\u0000', which is the null character.
Which of the following keywords is used to define an interface in Java?
Answer: A
Explanation: The interface keyword is used to define an interface in Java.
Which method in Java is used to start the execution of a thread?
Answer: C
Explanation: The start() method is used to begin the execution of a thread.
How do you declare a multi-dimensional array in Java?
Explanation: Both int array[][]; and int[] array[]; are valid ways to declare a multi-dimensional array.
What does the throw keyword do in Java?
Explanation: The throw keyword is used to explicitly throw an exception in Java.
Which method is used to convert a string to lowercase in Java?
Explanation: The toLowerCase() method is used to convert a string to lowercase.
Which of the following is a valid declaration of a float variable?
Answer: D
Explanation: Both float f = 3.14f; and float f = (float)3.14; are valid ways to declare a float variable.
What will happen if you try to access an array index that is out of bounds?
Explanation: Accessing an array index that is out of bounds will result in an ArrayIndexOutOfBoundsException.
How do you comment multiple lines in Java?
Explanation: The /* Comment */ syntax is used for multi-line comments in Java.
What is the output of System.out.println(10 != 5);?
Explanation: The expression evaluates to true since 10 is not equal to 5.
Which of the following will correctly create an instance of the String class?
Explanation: Both String str = new String(); and String str = "Hello"; are valid ways to create a String instance.
What does the final keyword mean when applied to a method?
Explanation: A method declared with the final keyword cannot be overridden by subclasses.
How do you declare a constant in Java?
Explanation: You declare a constant in Java using the final keyword.
Which of the following exceptions is thrown when attempting to convert a non-numeric string to a number?
Explanation: A NumberFormatException is thrown when attempting to convert a non-numeric string to a number.
ow can you convert a string to an integer in Java?
Explanation: Both Integer.parseInt(string); and Integer.valueOf(string); can be used to convert a string to an integer.
What is the primary purpose of the break statement?
Explanation: The break statement is used to exit a loop immediately.
How do you access the last element of an array named arr?
Explanation: The last element of an array is accessed using arr[arr.length - 1];.
hich keyword is used to indicate that a variable can be modified in a class?
Explanation: By default, class variables can be modified unless specified with final.
Which of the following statements is used to create a new object in Java?
Explanation: The correct syntax to create a new object is Object obj = new Object();.
What does Math.pow(2, 3) return?
Explanation: Math.pow(2, 3) returns 8, which is 2 raised to the power of 3.