OA Exams

  • web.groovymark@gmail.com
  • December 26, 2024

Question 21

Which of the following is not a valid Java identifier?

  • A. myVariable
  • B. 2ndVariable
  • C. variable_name
  • D. variableName

Answer: B

Explanation: Identifiers cannot begin with a digit.

Question 22

How can you create a constant in Java?

  • A. constant int MAX_VALUE = 100;
  • B. static int MAX_VALUE = 100;
  • C. final int MAX_VALUE = 100;
  • D. immutable int MAX_VALUE = 100;

Answer: C

Explanation: You create a constant in Java using the final keyword.

Question 23

What is the output of System.out.println(“Java”.length());?

  • A. 4
  • B. 5
  • C. 6
  • D. 0

Answer: B

Explanation: The length() method returns 4 because "Java" has four characters.

Question 24

Which of the following can be used to catch exceptions?

  • A. try
  • B. catch
  • C. finally
  • D. All of the above

Answer: D

Explanation: All options are part of the exception handling mechanism in Java.

Question 25

What does the volatile keyword indicate in Java?

  • A. The variable can be accessed by multiple threads.
  • B. The variable is constant.
  • C. The variable is immutable.
  • D. The variable cannot be changed.

Answer: A

Explanation: The volatile keyword indicates that a variable can be accessed by multiple threads, ensuring visibility

Question 26

What will the following code output? System.out.println(7 / 2);?

  • A. 3.5
  • B. 3
  • C. 4
  • D. Error

Correct Answer: c) Streamlined processes and reduced manual intervention

Explanation: Cloud automation tools streamline processes by reducing manual
intervention, which increases efficiency and consistency.

Question 27

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;

Answer: B

Explanation: Integer division discards the decimal part, resulting in 3.

Question 28

Which operator is used to compare two values for equality in Java?

  • A. =
  • B. ==
  • C. ===
  • D. !=

Answer: B

Explanation: The == operator is used to compare two values for equality in Java.

Question 29

Which method is used to read a line of text from the console?

  • A. System.in.readLine();
  • B. Scanner.nextLine();
  • C. BufferedReader.read();
  • D. Console.readLine();

Answer: B

Explanation: The Scanner.nextLine(); method is used to read a line of text from the console.

Question 30

What is the result of 5 + 10 + “20”?

  • A. 15
  • B. 20
  • C. 1520
  • D. Error

Answer: C

Explanation: The expression evaluates to "1520" due to string concatenation.

Question 31

How do you declare a method that returns nothing?

  • A. void myMethod() {}
  • B. null myMethod() {}
  • C. myMethod() {}
  • D. empty myMethod() {}

Answer: A

Explanation: The void keyword indicates that the method does not return a value.

Question 32

What is the output of System.out.println(5.0 / 0);?

  • A. Infinity
  • B. 0
  • C. NaN
  • D. Error

Answer: A

Explanation: Dividing a positive floating-point number by zero results in positive infinity

Question 33

Which of the following data types is used to represent true/false values in Java?

  • A. int
  • B. char
  • C. boolean
  • D. String

Answer: C

Explanation: The boolean data type is used to represent true/false values in Java.

Question 34

 How do you instantiate an object of a class named Dog?

  • A. Dog myDog;
  • B. Dog myDog = new Dog();
  • C. new Dog myDog;
  • D. Dog myDog = Dog();

Answer: B

Explanation: The correct way to instantiate an object is Dog myDog = new Dog();.

Question 35

What will be the output of the following code? System.out.println(2 + 3 + ” apples”);

  • A. 5 apples
  • B. 23 apples
  • C. apples 5
  • D. Error

Answer: A

Explanation: The expression evaluates to "5 apples" due to string concatenation.

Question 36

Which of the following is not a valid access modifier in Java?

  • A. public
  • B. private
  • C. protected
  • D. secure

Answer: D

Explanation: secure is not a valid access modifier in Java.

Question 37

Which keyword is used to create a subclass in Java?

  • A. extends
  • B. inherits
  • C. subclass
  • D. derived

Answer: A

Explanation: The extends keyword is used to create a subclass in Java.

Question 38

How do you declare a method with parameters in Java?

  • A. void myMethod(int a) {}
  • B. void myMethod(a int) {}
  • C. myMethod(int a) {}
  • D. void myMethod(a: int) {}

Answer: A

Explanation: The correct syntax to declare a method with parameters is void myMethod(int a) {}.

Question 39

What is the result of System.out.println(3 + 4 + 5);?

  • A. 12
  • B. 7
  • C. 345
  • D. Error

Answer: A

Explanation: The expression evaluates to 12 since all numbers are added together.

Question 40

How can you prevent a class from being instantiated?

  • A. By using the final keyword
  • B. By declaring the class as abstract
  • C. By using the static keyword
  • D. By declaring a private constructor

Answer: B

Explanation: Declaring a class as abstract prevents it from being instantiated directly.

Complete the Captcha to view next question set.

Tags

Prev Post
WGU D286 Practice Exam Questions – Set 4 – Part 1