Skip to content

Java Programming · Final project

Test

Step 1 of 2

Java 1 Final Test - Multiple Choice

Answer the following multiple choice questions to test your knowledge of Java 1 concepts including data types, conditionals, loops, methods, and arrays.

Quick check

  1. 1. What will the following code print? System.out.println("Hello, World!");

  2. 2. Which of the following is a correct way to declare a variable in Java?

  3. 3. What is the correct way to create an object in Java?

  4. 4. What is the output of the following code? int x = 5; int y = 10; if (x > y) { System.out.println("x is greater than y"); } else { System.out.println("x is less than or equal to y"); }

  5. 5. Which of the following is an example of an array in Java?

  6. 6. What will the following code snippet do? ArrayList<Integer> numbers = new ArrayList<>(); numbers.add(1); numbers.add(2); numbers.add(3); numbers.add(4); System.out.println(numbers);

  7. 7. Which statement correctly uses a loop to print numbers 0 to 9?

  8. 8. What does the following code do? for (int i = 0; i < 3; i++) { System.out.println(i); }

  9. 9. How do you define a method in Java?

  10. 10. What will the following code output? public static String greet(String name) { return "Hello, " + name; } public static void main(String[] args) { System.out.println(greet("Alice")); }

  11. 11. Which of the following is NOT a valid way to create a String in Java?

  12. 12. What is the result of 3 + "abc" in Java?

  13. 13. Which of the following is used to comment out multiple lines in Java?

  14. 14. What is the output of the following code? int x = 5; System.out.println(x > 3 && x < 10);

  15. 15. Which of the following is used to remove an item from an ArrayList by its index?

  16. 16. What is the output of the following code? System.out.println(Math.pow(2, 3));

  17. 17. Which of the following is used to format strings in Java?

  18. 18. What is the result of 10 / 3 in Java?

  19. 19. Which of the following is used to get the length of an array in Java?

  20. 20. What is the output of the following code? System.out.println(Boolean.valueOf(false) + " " + Boolean.valueOf(true) + " " + Boolean.valueOf(""));