Java Programming Practice Questions
1. What is the correct syntax to declare a variable that stores an integer value in Java?
A) int number;
B) integer number;
C) num int;
D) number int;
2. Which Java class is commonly used to read user input from the console?
A) [Link]
B) Scanner
C) InputReader
D) BufferedReader
3. What will be the output of the following code?
int x = 5;
[Link](++x);
A) 5
B) 6
C) 4
D) Compilation error
4. Which loop is guaranteed to execute at least once?
A) for loop
B) while loop
C) do-while loop
D) foreach loop
5. In Java, what is the default value of a boolean variable?
A) true
B) false
C) 0
D) null
6. What is the output of the following code snippet?
int a = 10;
int b = 20;
[Link](a + b);
A) 1020
B) 30
C) a + b
D) Compilation error
7. Which keyword is used to create a subclass in Java?
A) implements
B) inherits
C) extends
D) super
8. What does the break statement do in a loop?
A) Skips the current iteration
B) Exits the loop entirely
C) Pauses the loop
D) Restarts the loop
9. Which of the following is not a primitive data type in Java?
A) int
B) String
C) char
D) boolean
10. How do you start the execution of a Java program?
A) By calling the start() method
B) By defining the main() method
C) By creating a constructor
D) By importing the [Link] package
11. What is the correct syntax to declare a variable that stores an integer value in Java?
A) int number;
B) integer number;
C) num int;
D) number int;
12. Which Java class is commonly used to read user input from the console?
A) [Link]
B) Scanner
C) InputReader
D) BufferedReader
13. What will be the output of the following code?
int x = 5;
[Link](++x);
A) 5
B) 6
C) 4
D) Compilation error
14. Which loop is guaranteed to execute at least once?
A) for loop
B) while loop
C) do-while loop
D) foreach loop
15. In Java, what is the default value of a boolean variable?
A) true
B) false
C) 0
D) null
16. What is the output of the following code snippet?
int a = 10;
int b = 20;
[Link](a + b);
A) 1020
B) 30
C) a + b
D) Compilation error
17. Which keyword is used to create a subclass in Java?
A) implements
B) inherits
C) extends
D) super
18. What does the break statement do in a loop?
A) Skips the current iteration
B) Exits the loop entirely
C) Pauses the loop
D) Restarts the loop
19. Which of the following is not a primitive data type in Java?
A) int
B) String
C) char
D) boolean
20. How do you start the execution of a Java program?
A) By calling the start() method
B) By defining the main() method
C) By creating a constructor
D) By importing the [Link] package
21. What is the correct syntax to declare a variable that stores an integer value in Java?
A) int number;
B) integer number;
C) num int;
D) number int;
22. Which Java class is commonly used to read user input from the console?
A) [Link]
B) Scanner
C) InputReader
D) BufferedReader
23. What will be the output of the following code?
int x = 5;
[Link](++x);
A) 5
B) 6
C) 4
D) Compilation error
24. Which loop is guaranteed to execute at least once?
A) for loop
B) while loop
C) do-while loop
D) foreach loop
25. In Java, what is the default value of a boolean variable?
A) true
B) false
C) 0
D) null
26. What is the output of the following code snippet?
int a = 10;
int b = 20;
[Link](a + b);
A) 1020
B) 30
C) a + b
D) Compilation error
27. Which keyword is used to create a subclass in Java?
A) implements
B) inherits
C) extends
D) super
28. What does the break statement do in a loop?
A) Skips the current iteration
B) Exits the loop entirely
C) Pauses the loop
D) Restarts the loop
29. Which of the following is not a primitive data type in Java?
A) int
B) String
C) char
D) boolean
30. How do you start the execution of a Java program?
A) By calling the start() method
B) By defining the main() method
C) By creating a constructor
D) By importing the [Link] package
31. What is the correct syntax to declare a variable that stores an integer value in Java?
A) int number;
B) integer number;
C) num int;
D) number int;
32. Which Java class is commonly used to read user input from the console?
A) [Link]
B) Scanner
C) InputReader
D) BufferedReader
33. What will be the output of the following code?
int x = 5;
[Link](++x);
A) 5
B) 6
C) 4
D) Compilation error
34. Which loop is guaranteed to execute at least once?
A) for loop
B) while loop
C) do-while loop
D) foreach loop
35. In Java, what is the default value of a boolean variable?
A) true
B) false
C) 0
D) null
36. What is the output of the following code snippet?
int a = 10;
int b = 20;
[Link](a + b);
A) 1020
B) 30
C) a + b
D) Compilation error
37. Which keyword is used to create a subclass in Java?
A) implements
B) inherits
C) extends
D) super
38. What does the break statement do in a loop?
A) Skips the current iteration
B) Exits the loop entirely
C) Pauses the loop
D) Restarts the loop
39. Which of the following is not a primitive data type in Java?
A) int
B) String
C) char
D) boolean
40. How do you start the execution of a Java program?
A) By calling the start() method
B) By defining the main() method
C) By creating a constructor
D) By importing the [Link] package
41. What is the correct syntax to declare a variable that stores an integer value in Java?
A) int number;
B) integer number;
C) num int;
D) number int;
42. Which Java class is commonly used to read user input from the console?
A) [Link]
B) Scanner
C) InputReader
D) BufferedReader
43. What will be the output of the following code?
int x = 5;
[Link](++x);
A) 5
B) 6
C) 4
D) Compilation error
44. Which loop is guaranteed to execute at least once?
A) for loop
B) while loop
C) do-while loop
D) foreach loop
45. In Java, what is the default value of a boolean variable?
A) true
B) false
C) 0
D) null
46. What is the output of the following code snippet?
int a = 10;
int b = 20;
[Link](a + b);
A) 1020
B) 30
C) a + b
D) Compilation error
47. Which keyword is used to create a subclass in Java?
A) implements
B) inherits
C) extends
D) super
48. What does the break statement do in a loop?
A) Skips the current iteration
B) Exits the loop entirely
C) Pauses the loop
D) Restarts the loop
49. Which of the following is not a primitive data type in Java?
A) int
B) String
C) char
D) boolean
50. How do you start the execution of a Java program?
A) By calling the start() method
B) By defining the main() method
C) By creating a constructor
D) By importing the [Link] package
51. What is the correct syntax to declare a variable that stores an integer value in Java?
A) int number;
B) integer number;
C) num int;
D) number int;
52. Which Java class is commonly used to read user input from the console?
A) [Link]
B) Scanner
C) InputReader
D) BufferedReader
53. What will be the output of the following code?
int x = 5;
[Link](++x);
A) 5
B) 6
C) 4
D) Compilation error
54. Which loop is guaranteed to execute at least once?
A) for loop
B) while loop
C) do-while loop
D) foreach loop
55. In Java, what is the default value of a boolean variable?
A) true
B) false
C) 0
D) null
56. What is the output of the following code snippet?
int a = 10;
int b = 20;
[Link](a + b);
A) 1020
B) 30
C) a + b
D) Compilation error
57. Which keyword is used to create a subclass in Java?
A) implements
B) inherits
C) extends
D) super
58. What does the break statement do in a loop?
A) Skips the current iteration
B) Exits the loop entirely
C) Pauses the loop
D) Restarts the loop
59. Which of the following is not a primitive data type in Java?
A) int
B) String
C) char
D) boolean
60. How do you start the execution of a Java program?
A) By calling the start() method
B) By defining the main() method
C) By creating a constructor
D) By importing the [Link] package
61. What is the correct syntax to declare a variable that stores an integer value in Java?
A) int number;
B) integer number;
C) num int;
D) number int;
62. Which Java class is commonly used to read user input from the console?
A) [Link]
B) Scanner
C) InputReader
D) BufferedReader
63. What will be the output of the following code?
int x = 5;
[Link](++x);
A) 5
B) 6
C) 4
D) Compilation error
64. Which loop is guaranteed to execute at least once?
A) for loop
B) while loop
C) do-while loop
D) foreach loop
65. In Java, what is the default value of a boolean variable?
A) true
B) false
C) 0
D) null
66. What is the output of the following code snippet?
int a = 10;
int b = 20;
[Link](a + b);
A) 1020
B) 30
C) a + b
D) Compilation error
67. Which keyword is used to create a subclass in Java?
A) implements
B) inherits
C) extends
D) super
68. What does the break statement do in a loop?
A) Skips the current iteration
B) Exits the loop entirely
C) Pauses the loop
D) Restarts the loop
69. Which of the following is not a primitive data type in Java?
A) int
B) String
C) char
D) boolean
70. How do you start the execution of a Java program?
A) By calling the start() method
B) By defining the main() method
C) By creating a constructor
D) By importing the [Link] package
Answer Key
1. A
2. B
3. B
4. C
5. B
6. B
7. C
8. B
9. B
10. B
11. A
12. B
13. B
14. C
15. B
16. B
17. C
18. B
19. B
20. B
21. A
22. B
23. B
24. C
25. B
26. B
27. C
28. B
29. B
30. B
31. A
32. B
33. B
34. C
35. B
36. B
37. C
38. B
39. B
40. B
41. A
42. B
43. B
44. C
45. B
46. B
47. C
48. B
49. B
50. B
51. A
52. B
53. B
54. C
55. B
56. B
57. C
58. B
59. B
60. B
61. A
62. B
63. B
64. C
65. B
66. B
67. C
68. B
69. B
70. B