OA Exams
Which of the following is not a valid Java identifier?
Answer: B
Explanation: Identifiers cannot begin with a digit.
How can you create a constant in Java?
Answer: C
Explanation: You create a constant in Java using the final keyword.
What is the output of System.out.println(“Java”.length());?
Explanation: The length() method returns 4 because "Java" has four characters.
Which of the following can be used to catch exceptions?
Answer: D
Explanation: All options are part of the exception handling mechanism in Java.
What does the volatile keyword indicate in Java?
Answer: A
Explanation: The volatile keyword indicates that a variable can be accessed by multiple threads, ensuring visibility
What will the following code output? System.out.println(7 / 2);?
Correct Answer: c) Streamlined processes and reduced manual interventionExplanation: Cloud automation tools streamline processes by reducing manual intervention, which increases efficiency and consistency.
How do you declare an array of integers in Java?
· A. int[] arr;
· B. int arr[];
· C. Both A and B
· D. array int arr;
Explanation: Integer division discards the decimal part, resulting in 3.
Which operator is used to compare two values for equality in Java?
Explanation: The == operator is used to compare two values for equality in Java.
Which method is used to read a line of text from the console?
Explanation: The Scanner.nextLine(); method is used to read a line of text from the console.
What is the result of 5 + 10 + “20”?
Explanation: The expression evaluates to "1520" due to string concatenation.
How do you declare a method that returns nothing?
Explanation: The void keyword indicates that the method does not return a value.
What is the output of System.out.println(5.0 / 0);?
Explanation: Dividing a positive floating-point number by zero results in positive infinity
Which of the following data types is used to represent true/false values in Java?
Explanation: The boolean data type is used to represent true/false values in Java.
How do you instantiate an object of a class named Dog?
Explanation: The correct way to instantiate an object is Dog myDog = new Dog();.
What will be the output of the following code? System.out.println(2 + 3 + ” apples”);
Explanation: The expression evaluates to "5 apples" due to string concatenation.
Which of the following is not a valid access modifier in Java?
Explanation: secure is not a valid access modifier in Java.
Which keyword is used to create a subclass in Java?
Explanation: The extends keyword is used to create a subclass in Java.
How do you declare a method with parameters in Java?
Explanation: The correct syntax to declare a method with parameters is void myMethod(int a) {}.
What is the result of System.out.println(3 + 4 + 5);?
Explanation: The expression evaluates to 12 since all numbers are added together.
How can you prevent a class from being instantiated?
Explanation: Declaring a class as abstract prevents it from being instantiated directly.