Java quiz online test Basic Java quiz

java_quiz

java quiz online MCQ

 

1.  What does JVM stand for?
a) Java Virtual Machine
b) Java Variable Manager
c) JavaScript Virtual Machine
d) Just Virtual Memory
Answer: a) Java Virtual Machine

2. Which keyword is used to create a constant in Java?
a) final
b) const
c) static
d) let
Answer: a) final

3. What is the default value of the elements in an array of integers in Java?
a) 0
b) 1
c) null
d) -1
Answer: a) 0

4. What is the process of converting an object into a stream of bytes called in Java?
a) Serialization
b) Deserialization
c) Objectifying
d) Bytecoding
Answer: a) Serialization

5. Which data type in Java is used to create a variable that can store text?
a) int
b) String
c) char
d) text
Answer: b) String

6. What does the “static” keyword mean in Java?
a) It makes a variable constant.
b) It allows access to the variable from any method in the class.
c) It creates a new instance of the variable.
d) It makes the variable accessible only within the same method.
Answer: b) It allows access to the variable from any method in the class.

7. What is the result of 15 % 2 in Java?
a) 7
b) 8
c) 1
d) 0
Answer: c) 1

8. Which loop is guaranteed to execute at least once in Java?
a) for loop
b) while loop
c) do-while loop
d) foreach loop
Answer: c) do-while loop

9. Which keyword is used to refer to the current object in Java?
a) this
b) self
c) that
d) here
Answer: a) this

10. What is the correct way to create an object in Java?
a) Object myObj = new Object();
b) Object myObj = create Object;
c) Object myObj = Object.create();
d) Object myObj = createObject();
Answer: a) Object myObj = new Object();

11. Which access modifier restricts access the least in Java?
a) private
b) public
c) protected
d) default (no modifier)
Answer: b) public

12. What is the purpose of the “break” statement in Java?
a) To exit a loop or switch statement.
b) To skip the current iteration of a loop.
c) To jump to a specific point in the code.
d) To terminate the program.
Answer: a) To exit a loop or switch statement.

13. Which keyword is used to prevent a method from being overridden in Java?
a) final
b) override
c) static
d) private
Answer: a) final

14. What is the result of 2 + 5.0 in Java?
a) 7.0 (double)
b) 7 (int)
c) 5.0 (double)
d) Error
Answer: a) 7.0 (double)

15. Which of the following is not a Java keyword?
a) yield
b) module
c) var
d) function
Answer: d) function

16.  What is the return type of the “main” method in Java?
a) void
b) int
c) String
d) main
Answer: b) int

17. Which class is at the top of the Java class hierarchy?
a) Object
b) Main
c) Base
d) Top
Answer: a) Object

18. What is the result of (true && false) in Java?
a) true
b) false
c) Error
d) Cannot be determined
Answer: b) false

19. How is memory allocated for objects in Java?
a) Using malloc()
b) Automatically by the JVM
c) Using new()
d) Using alloc()
Answer: b) Automatically by the JVM

20. Which method is called when an object is garbage collected in Java?
a) finalize()
b) destroy()
c) clean()
d) release()
Answer: a) finalize()

21. core java quiz online ?

What does JVM stand for?
a) Java Virtual Machine
b) Java Virtual Memory
c) Java Variable Machine
d) Java Verification Machine
Answer: a) Java Virtual Machine

22. Which of the following is NOT a primitive data type in Java?
a) int
b) float
c) string
d) boolean
Answer: c) string

23. What is the default value of a boolean variable in Java?
a) false
b) true
c) 0
d) null
Answer: a) false

24. Which keyword is used to declare a constant in Java?
a) const
b) final
c) static
d) constant
Answer: b) final

25. What is the output of System.out.println(5 + “5”) in Java?
a) 55
b) 10
c) 5 + 5
d) Error
Answer: a) 55

26. What is the superclass of all classes in Java?
a) Main
b) Object
c) Super
d) Base
Answer: b) Object

27. Which keyword is used to prevent a method from being overridden in a subclass?
a) override
b) final
c) private
d) protect
Answer: b) final

28. What is the correct syntax to create an array in Java?
a) int arr = {1, 2, 3};
b) int arr[] = new int[3];
c) int arr() = new int[];
d) array arr = [1, 2, 3];
Answer: b) int arr[] = new int[3];

29. Which of the following is NOT a looping statement in Java?
a) for
b) loop
c) while
d) do-while
Answer: b) loop

30. What is the role of the static keyword in Java?
a) To create global variables
b) To make a method or variable belong to the class, not the instance
c) To allow access to private members
d) To declare constants
Answer: b) To make a method or variable belong to the class, not the instance

31. Which exception is thrown when an array is accessed with an illegal index in Java?
a) ArrayOutOfBoundsException
b) ArrayIndexException
c) IndexOutOfBoundsException
d) ArrayIllegalIndexException
Answer: a) ArrayOutOfBoundsException

32.  What is the use of the super keyword in Java?
a) To call the superclass constructor
b) To access the superclass’s private members
c) To call overridden methods
d) To declare a superclass
Answer: a) To call the superclass constructor

33. Which method is used to compare two strings in Java?
a) compare()
b) equals()
c) compareTo()
d) == operator
Answer: b) equals()

34. How are objects eligible for garbage collection in Java?
a) When there are no references to the object
b) When the object is explicitly marked for deletion
c) When the program ends
d) When the object is out of scope
Answer: a) When there are no references to the object

35. What is the return type of the main() method in Java?
a) void
b) int
c) String
d) float
Answer: a) void

Basic java quiz online

 

36. What does JDK stand for?
a) Java Development Kit
b) Java Developer Kit
c) Java Deployment Kit
d) Java Debugging Kit
Answer: a) Java Development Kit

37. Which keyword is used for creating a new instance of a class in Java?
a) new
b) create
c) instance
d) object
Answer: a) new

38. What is the output of System.out.println(10 > 5) in Java?
a) true
b) false
c) 10
d) Error
Answer: a) true

39. Which statement is used to exit from a loop in Java?
a) break
b) exit
c) stop
d) end
Answer: a) break

40. What is the syntax for a single-line comment in Java?
a) //
b) /*
c) #
d) ‘
Answer: a) //

41. Which of the following is not a valid identifier in Java?
a) myVariable
b) _myVariable
c) 2myVariable
d) $myVariable
Answer: c) 2myVariable

42. What is the default value of an integer variable in Java?
a) 0
b) 1
c) null
d) -1
Answer: a) 0

43. Which method is used to obtain the length of a string in Java?
a) length()
b) getSize()
c) count()
d) size()
Answer: a) length()

44. What does the void keyword indicate in a method declaration in Java?
a) It returns nothing
b) It is a placeholder for future implementation
c) It is a data type
d) It throws an exception
Answer: a) It returns nothing

45. Which operator is used for string concatenation in Java?
a) +
b) &
c) ++
d) ||
Answer: a) +

46. Which class is used to read input from the keyboard in Java?
a) Console
b) Scanner
c) SystemInput
d) KeyboardReader
Answer: b) Scanner

47. What is the access modifier used for variables and methods that are accessible within the same package, but not outside it?
a) public
b) private
c) protected
d) default (no modifier)
Answer: d) default (no modifier)

48. What is the correct way to declare a constant variable in Java?
a) constant int x = 5;
b) final int x = 5;
c) const int x = 5;
d) static int x = 5;
Answer: b) final int x = 5;

49. Which of the following is NOT a Java keyword?
a) class
b) object
c) try
d) catch
Answer: b) object

50. What is the role of the keyword in Java?
a) Refers to the current class instance
b) Refers to the parent class
c) Refers to a static variable
d) Refers to the superclass
Answer: a) Refers to the current class instance

java quiz online?

51. What does JVM stand for?
a) Java Virtual Machine
b) Java Virtual Memory
c) Java Variable Machine
d) Java Verification Machine
Answer: a) Java Virtual Machine

52. Which keyword is used to define a constant in Java?
a) const
b) final
c) static
d) constant
Answer: b) final

53. What is the output of System.out.println(5 / 2) in Java?
a) 2.5
b) 2
c) 2.0
d) Error
Answer: b) 2

54. Which loop is used to iterate over elements of an array or a collection in Java?
a) for
b) while
c) do-while
d) foreach
Answer: d) foreach

55. What is the superclass of all classes in Java?
a) Base
b) Top
c) Main
d) Object
Answer: d) Object

56. What is the correct way to declare a method in Java that doesn’t return any value?
a) void myMethod()
b) int myMethod()
c) myMethod void()
d) myMethod returns void
Answer: a) void myMethod()

57. Which operator is used to compare two values for equality in Java?
a) ==
b) =
c) ===
d) !=
Answer: a) ==

58. What is the correct way to initialize an array in Java?
a) int[] arr = new int[5]{1, 2, 3, 4, 5};
b) int arr[] = {1, 2, 3, 4, 5};
c) array arr = [1, 2, 3, 4, 5];
d) int arr[5] = {1, 2, 3, 4, 5};
Answer: b) int arr[] = {1, 2, 3, 4, 5};

59. Which keyword is used to refer to the current instance of the class in Java?
a) self
b) this
c) me
d) current
Answer: b) this

60. What is the purpose of the break statement in Java?
a) To exit a loop or switch statement
b) To skip the current iteration of a loop
c) To jump to a specific point in the code
d) To terminate the program
Answer: a) To exit a loop or switch statement

61. What is the default value of a boolean variable in Java?
a) true
b) false
c) 0
d) null
Answer: b) false

62. Which method is used to read input from the keyboard in Java?
a) System.in.read()
b) Console.read()
c) Scanner.nextLine()
d) Keyboard.getInput()
Answer: c) Scanner.nextLine()

63. What is the return type of the main() method in Java?
a) void
b) int
c) String
d) boolean
Answer: b) int

64. Which access modifier restricts access to the class members within the same package only?
a) private
b) protected
c) public
d) default (no modifier)
Answer: d) default (no modifier)

65. What is the role of the super keyword in Java?
a) Refers to the subclass instance
b) Calls the superclass constructor
c) Refers to a static variable
d) Terminates the program
Answer: b) Calls the superclass constructor

mcq java

66. What does JDK stand for?
a) Java Development Kit
b) Java Developer Kit
c) Java Deployment Kit
d) Java Debugging Kit
Answer: a) Java Development Kit

67. Which keyword is used to create a subclass in Java?
a) extend
b) subclass
c) inherits
d) super
Answer: a) extend

68. What is the output of System.out.println(“Java”.substring(1, 3)) in Java?
a) “Jav”
b) “Ja”
c) “av”
d) “ava”
Answer: c) “av”

69. Which data type is used to store a single Unicode character in Java?
a) char
b) character
c) letter
d) unicode
Answer: a) char

70. What is the result of 10 == 10.0 in Java?
a) true
b) false
c) 1
d) Error
Answer: a) true

71. Which keyword is used to prevent method overriding in Java?
a) final
b) static
c) override
d) private
Answer: a) final

72. What is the purpose of the super() method in a constructor?
a) Calls the superclass constructor
b) Calls the overridden method
c) Creates a new instance of the superclass
d) Terminates the program
Answer: a) Calls the superclass constructor

73. Which of the following is NOT a valid Java identifier?
a) $value
b) _variable
c) 3var
d) myVar
Answer: c) 3var

74. What is the output of System.out.println(5 + 5 + “Java”) in Java?
a) 10Java
b) Java10
c) 55Java
d) Error
Answer: c) 55Java

75. Which loop is guaranteed to execute at least once in Java?
a) for loop
b) while loop
c) do-while loop
d) foreach loop
Answer: c) do-while loop

76. What is the correct way to declare a constant variable in Java within a class?
a) const int CONSTANT_VALUE = 10;
b) final static int CONSTANT_VALUE = 10;
c) static const int CONSTANT_VALUE = 10;
d) final int CONSTANT_VALUE = 10;
Answer: b) final static int CONSTANT_VALUE = 10;

77. Which method is used to obtain the length of an array in Java?
a) length()
b) getSize()
c) size()
d) count()
Answer: a) length()

78. Which of the following is NOT a Java access modifier?
a) default
b) private
c) public
d) protected
Answer: a) default

79. What is the correct syntax for a multi-line comment in Java?
a) /* comment */
b) // comment //
c) # comment #
d) ”’ comment ”’
Answer: a) / comment /

80. What is the purpose of the toString() method in Java?
a) Converts a string to uppercase
b) Converts an object to its string representation
c) Converts a string to lowercase
d) Compares two strings for equality
Answer: b) Converts an object to its string representation

java quiz online MCQ

81. What does JVM stand for?
a) Java Virtual Machine
b) Java Variable Manager
c) JavaScript Virtual Machine
d) Just Virtual Memory
Answer: a) Java Virtual Machine

82. Which keyword is used to create a constant in Java?
a) final
b) const
c) static
d) let
Answer: a) final

83. What is the default value of the elements in an array of integers in Java?
a) 0
b) 1
c) null
d) -1
Answer: a) 0

84. What is the process of converting an object into a stream of bytes called in Java?
a) Serialization
b) Deserialization
c) Objectifying
d) Bytecoding
Answer: a) Serialization

85. Which data type in Java is used to create a variable that can store text?
a) int
b) String
c) char
d) text
Answer: b) String

86. What does the “static” keyword mean in Java?
a) It makes a variable constant.
b) It allows access to the variable from any method in the class.
c) It creates a new instance of the variable.
d) It makes the variable accessible only within the same method.
Answer: b) It allows access to the variable from any method in the class.

87. What is the result of 15 % 2 in Java?
a) 7
b) 8
c) 1
d) 0
Answer: c) 1

88. Which loop is guaranteed to execute at least once in Java?
a) for loop
b) while loop
c) do-while loop
d) foreach loop
Answer: c) do-while loop

89. Which keyword is used to refer to the current object in Java?
a) this
b) self
c) that
d) here
Answer: a) this

90. What is the correct way to create an object in Java?
a) Object myObj = new Object();
b) Object myObj = create Object;
c) Object myObj = Object.create();
d) Object myObj = createObject();
Answer: a) Object myObj = new Object();

91. Which access modifier restricts access the least in Java?
a) private
b) public
c) protected
d) default (no modifier)
Answer: b) public

92. What is the purpose of the “break” statement in Java?
a) To exit a loop or switch statement.
b) To skip the current iteration of a loop.
c) To jump to a specific point in the code.
d) To terminate the program.
Answer: a) To exit a loop or switch statement.

93. Which keyword is used to prevent a method from being overridden in Java?
a) final
b) override
c) static
d) private
Answer: a) final

94. What is the result of 2 + 5.0 in Java?
a) 7.0 (double)
b) 7 (int)
c) 5.0 (double)
d) Error
Answer: a) 7.0 (double)

95. Which of the following is not a Java keyword?
a) yield
b) module
c) var
d) function
Answer: d) function

96. What is the return type of the “main” method in Java?
a) void
b) int
c) String
d) main
Answer: b) int

97. Which class is at the top of the Java class hierarchy?
a) Object
b) Main
c) Base
d) Top
Answer: a) Object

98. What is the result of (true && false) in Java?
a) true
b) false
c) Error
d) Cannot be determined
Answer: b) false

99. How is memory allocated for objects in Java?
a) Using malloc()
b) Automatically by the JVM
c) Using new()
d) Using alloc()
Answer: b) Automatically by the JVM

100. Which method is called when an object is garbage collected in Java?
a) finalize()
b) destroy()
c) clean()
d) release()
Answer: a) finalize()

 

core java quiz online ?

 

101. What does JVM stand for?

a) Java Virtual Machine
b) Java Virtual Memory
c) Java Variable Machine
d) Java Verification Machine
Answer: a) Java Virtual Machine

102. Which of the following is NOT a primitive data type in Java?
a) int
b) float
c) string
d) boolean
Answer: c) string

103. What is the default value of a boolean variable in Java?
a) false
b) true
c) 0
d) null
Answer: a) false

104. Which keyword is used to declare a constant in Java?
a) const
b) final
c) static
d) constant
Answer: b) final

105. What is the output of System.out.println(5 + “5”) in Java?
a) 55
b) 10
c) 5 + 5
d) Error
Answer: a) 55

106. What is the superclass of all classes in Java?
a) Main
b) Object
c) Super
d) Base
Answer: b) Object

107. Which keyword is used to prevent a method from being overridden in a subclass?
a) override
b) final
c) private
d) protect
Answer: b) final

108. What is the correct syntax to create an array in Java?
a) int arr = {1, 2, 3};
b) int arr[] = new int[3];
c) int arr() = new int[];
d) array arr = [1, 2, 3];
Answer: b) int arr[] = new int[3];

109. Which of the following is NOT a looping statement in Java?
a) for
b) loop
c) while
d) do-while
Answer: b) loop

110. What is the role of the static keyword in Java?
a) To create global variables
b) To make a method or variable belong to the class, not the instance
c) To allow access to private members
d) To declare constants
Answer: b) To make a method or variable belong to the class, not the instance

111. Which exception is thrown when an array is accessed with an illegal index in Java?
a) ArrayOutOfBoundsException
b) ArrayIndexException
c) IndexOutOfBoundsException
d) ArrayIllegalIndexException
Answer: a) ArrayOutOfBoundsException

112. What is the use of the super keyword in Java?
a) To call the superclass constructor
b) To access the superclass’s private members
c) To call overridden methods
d) To declare a superclass
Answer: a) To call the superclass constructor

113. Which method is used to compare two strings in Java?
a) compare()
b) equals()
c) compareTo()
d) == operator
Answer: b) equals()

114. How are objects eligible for garbage collection in Java?
a) When there are no references to the object
b) When the object is explicitly marked for deletion
c) When the program ends
d) When the object is out of scope
Answer: a) When there are no references to the object

115. What is the return type of the main() method in Java?
a) void
b) int
c) String
d) float
Answer: a) void

Basic java quiz online

 

116. What does JDK stand for?
a) Java Development Kit
b) Java Developer Kit
c) Java Deployment Kit
d) Java Debugging Kit
Answer: a) Java Development Kit

117. Which keyword is used for creating a new instance of a class in Java?
a) new
b) create
c) instance
d) object
Answer: a) new

118. What is the output of System.out.println(10 > 5) in Java?
a) true
b) false
c) 10
d) Error
Answer: a) true

119. Which statement is used to exit from a loop in Java?
a) break
b) exit
c) stop
d) end
Answer: a) break

120. What is the syntax for a single-line comment in Java?
a) //
b) /*
c) #
d) ‘
Answer: a) //

121. Which of the following is not a valid identifier in Java?
a) myVariable
b) _myVariable
c) 2myVariable
d) $myVariable
Answer: c) 2myVariable

122. What is the default value of an integer variable in Java?
a) 0
b) 1
c) null
d) -1
Answer: a) 0

123. Which method is used to obtain the length of a string in Java?
a) length()
b) getSize()
c) count()
d) size()
Answer: a) length()

124. What does the void keyword indicate in a method declaration in Java?
a) It returns nothing
b) It is a placeholder for future implementation
c) It is a data type
d) It throws an exception
Answer: a) It returns nothing

125. Which operator is used for string concatenation in Java?
a) +
b) &
c) ++
d) ||
Answer: a) +

126. Which class is used to read input from the keyboard in Java?
a) Console
b) Scanner
c) SystemInput
d) KeyboardReader
Answer: b) Scanner

127. What is the access modifier used for variables and methods that are accessible within the same package, but not outside it?
a) public
b) private
c) protected
d) default (no modifier)
Answer: d) default (no modifier)

128. What is the correct way to declare a constant variable in Java?
a) constant int x = 5;
b) final int x = 5;
c) const int x = 5;
d) static int x = 5;
Answer: b) final int x = 5;

129. Which of the following is NOT a Java keyword?
a) class
b) object
c) try
d) catch
Answer: b) object

130. What is the role of the keyword in Java?
a) Refers to the current class instance
b) Refers to the parent class
c) Refers to a static variable
d) Refers to the superclass
Answer: a) Refers to the current class instance

java quiz online?

131. What does JVM stand for?
a) Java Virtual Machine
b) Java Virtual Memory
c) Java Variable Machine
d) Java Verification Machine
Answer: a) Java Virtual Machine

132. Which keyword is used to define a constant in Java?
a) const
b) final
c) static
d) constant
Answer: b) final

133. What is the output of System.out.println(5 / 2) in Java?
a) 2.5
b) 2
c) 2.0
d) Error
Answer: b) 2

134. Which loop is used to iterate over elements of an array or a collection in Java?
a) for
b) while
c) do-while
d) foreach
Answer: d) foreach

135. What is the superclass of all classes in Java?
a) Base
b) Top
c) Main
d) Object
Answer: d) Object

136. What is the correct way to declare a method in Java that doesn’t return any value?
a) void myMethod()
b) int myMethod()
c) myMethod void()
d) myMethod returns void
Answer: a) void myMethod()

137. Which operator is used to compare two values for equality in Java?
a) ==
b) =
c) ===
d) !=
Answer: a) ==

138. What is the correct way to initialize an array in Java?
a) int[] arr = new int[5]{1, 2, 3, 4, 5};
b) int arr[] = {1, 2, 3, 4, 5};
c) array arr = [1, 2, 3, 4, 5];
d) int arr[5] = {1, 2, 3, 4, 5};
Answer: b) int arr[] = {1, 2, 3, 4, 5};

139. Which keyword is used to refer to the current instance of the class in Java?
a) self
b) this
c) me
d) current
Answer: b) this

140. What is the purpose of the break statement in Java?
a) To exit a loop or switch statement
b) To skip the current iteration of a loop
c) To jump to a specific point in the code
d) To terminate the program
Answer: a) To exit a loop or switch statement

141. What is the default value of a boolean variable in Java?
a) true
b) false
c) 0
d) null
Answer: b) false

142. Which method is used to read input from the keyboard in Java?
a) System.in.read()
b) Console.read()
c) Scanner.nextLine()
d) Keyboard.getInput()
Answer: c) Scanner.nextLine()

143. What is the return type of the main() method in Java?
a) void
b) int
c) String
d) boolean
Answer: b) int

144. Which access modifier restricts access to the class members within the same package only?
a) private
b) protected
c) public
d) default (no modifier)
Answer: d) default (no modifier)

145. What is the role of the super keyword in Java?
a) Refers to the subclass instance
b) Calls the superclass constructor
c) Refers to a static variable
d) Terminates the program
Answer: b) Calls the superclass constructor

mcq java

 

146. What does JDK stand for?
a) Java Development Kit
b) Java Developer Kit
c) Java Deployment Kit
d) Java Debugging Kit
Answer: a) Java Development Kit

147. Which keyword is used to create a subclass in Java?
a) extend
b) subclass
c) inherits
d) super
Answer: a) extend

148. What is the output of System.out.println(“Java”.substring(1, 3)) in Java?
a) “Jav”
b) “Ja”
c) “av”
d) “ava”
Answer: c) “av”

149. Which data type is used to store a single Unicode character in Java?
a) char
b) character
c) letter
d) unicode
Answer: a) char

150. What is the result of 10 == 10.0 in Java?
a) true
b) false
c) 1
d) Error
Answer: a) true

151. Which keyword is used to prevent method overriding in Java?
a) final
b) static
c) override
d) private
Answer: a) final

152. What is the purpose of the super() method in a constructor?
a) Calls the superclass constructor
b) Calls the overridden method
c) Creates a new instance of the superclass
d) Terminates the program
Answer: a) Calls the superclass constructor

153. Which of the following is NOT a valid Java identifier?
a) $value
b) _variable
c) 3var
d) myVar
Answer: c) 3var

154. What is the output of System.out.println(5 + 5 + “Java”) in Java?
a) 10Java
b) Java10
c) 55Java
d) Error
Answer: c) 55Java

155. Which loop is guaranteed to execute at least once in Java?
a) for loop
b) while loop
c) do-while loop
d) foreach loop
Answer: c) do-while loop

156. What is the correct way to declare a constant variable in Java within a class?
a) const int CONSTANT_VALUE = 10;
b) final static int CONSTANT_VALUE = 10;
c) static const int CONSTANT_VALUE = 10;
d) final int CONSTANT_VALUE = 10;
Answer: b) final static int CONSTANT_VALUE = 10;

157. Which method is used to obtain the length of an array in Java?
a) length()
b) getSize()
c) size()
d) count()
Answer: a) length()

158. Which of the following is NOT a Java access modifier?
a) default
b) private
c) public
d) protected
Answer: a) default

159. What is the correct syntax for a multi-line comment in Java?
a) /* comment */
b) // comment //
c) # comment #
d) ”’ comment ”’
Answer: a) / comment /

160. What is the purpose of the toString() method in Java?
a) Converts a string to uppercase
b) Converts an object to its string representation
c) Converts a string to lowercase
d) Compares two strings for equality
Answer: b) Converts an object to its string representation

Feel free to utilize these for your Java multiple-choice quiz!

Leave a Reply