21. What is the purpose of the exit statement in Java?

  • To skip the current iteration of a loop and move to the next iteration.
  • To end the program execution.
  • To exit a loop or switch statement before its normal completion.
  • There is no exit statement in Java.

22. Which of the following is a valid use of the switch statement in Java?

  • Switching on a boolean variable.
  • Switching on a float variable.
  • Switching on a String variable.
  • Switching on an object reference variable.

23. What is the purpose of the for loop in Java?

  • To declare variables.
  • To perform arithmetic operations.
  • To perform conditional branching.
  • To repeatedly execute a block of code based on a condition.

24. What is the purpose of the while loop in Java?

  • To perform arithmetic operations.
  • To perform conditional branching.
  • To repeatedly execute a block of code based on a condition.
  • To declare variables.

25. What is the purpose of the for-each loop in Java?

  • To perform arithmetic operations.
  • To perform conditional branching.
  • To declare variables.
  • To iterate over elements of an array or a collection.

26. What is the purpose of the break statement in Java?

  • To terminate the program execution.
  • To skip the current iteration of a loop and move to the next iteration.
  • To continue with the next iteration of a loop.
  • To resume execution after the end of a loop.

27. What is the purpose of the continue statement in Java?

  • To terminate the program execution.
  • To skip the current iteration of a loop and move to the next iteration.
  • To exit a loop or switch statement before its normal completion.
  • To resume execution after the end of a loop.

28. What is the purpose of the ternary operator in Java?

  • To perform arithmetic operations.
  • To perform conditional branching.
  • To declare variables.
  • To iterate over elements of an array or a collection.

29. What is the purpose of the control flow statements in Java?

  • To perform arithmetic operations.
  • To perform conditional branching.
  • To declare variables.
  • To iterate over elements of an array or a collection.

30. What is the purpose of the switch case statement in Java?.

  • To perform arithmetic operations.
  • To perform conditional branching.
  • To declare variables.
  • To iterate over elements of an array or a collection.

Leave a Reply