OA Exams
What is the purpose of the this keyword in Java?
A. To reference the current class
B. To reference the current object
C. To call a constructor
D. To create an instance of a class
Answer: B
Explanation: The this keyword is used to reference the current object.
How do you declare a variable that can hold a decimal value in Java?
A. int myDecimal;
B. double myDecimal;
C. decimal myDecimal;
D. float myDecimal;
Explanation: The double data type is used to declare a variable that can hold decimal values.
Which of the following statements is true about the final keyword?
A. It can be applied to methods, variables, and classes.
B. It can only be applied to classes.
C. It can be applied only to methods.
D. It cannot be used with variables.
Answer: A
Explanation: The final keyword can be applied to methods, variables, and classes to restrict modifications.
What is the output of System.out.println(2 * 3 + 4 * 5);?
A. 22
B. 26
C. 29
D. 20
Explanation: The expression evaluates to 26 based on the order of operations.
How do you convert a primitive type to a wrapper type in Java?
A. Autoboxing
B. Boxing
C. Unboxing
D. Casting
Explanation: The process of converting a primitive type to a wrapper type is known as autoboxing.
What is the output of System.out.println(“2” + 3 + 1);?
A. 6
B. 231
C. 23
D. 1
Explanation: The expression evaluates to "231" due to string concatenation.
Which of the following is true about an interface in Java?
A. It can contain method implementations.
B. It can have instance variables.
C. It can extend multiple interfaces.
D. It cannot be instantiated.
Answer: C
Explanation: An interface can extend multiple interfaces, and it cannot have instance variables or implementations of methods.
How do you make a class final in Java?
A. By using the final keyword before the class name
B. By using the static keyword
C. By using the protected keyword
D. By using the private keyword
Explanation: A class is made final by using the final keyword before the class name.
What is the output of System.out.println(5 + “10”);?
A. 15
B. 510
C. 5.10
D. 5 + 10
Explanation: The expression evaluates to "510" due to string concatenation.
Which of the following is a feature of exception handling in Java?
A. It allows for error recovery.
B. It stops program execution.
C. It can handle only runtime exceptions.
D. It is mandatory for all methods.
Explanation: Exception handling allows for error recovery in a program.