Java - Language Fundamentals Questions and Answers

Practice Mode
Showing 10 of 39 questions
Q21
What is the default value of a boolean variable in Java?
  • A true
  • B Explanation: The default value of a boolean variable is false.
  • C 0
  • D null
Answer: Option B
Explanation: The default value of a boolean variable is false.
Q22
Which of the following is a valid main method declaration?
  • A public static void main(String args)
  • B Explanation: This is the correct syntax and order for the main method.
  • C void main(String[] args)
  • D public void static main(String args[])
Answer: Option B
Explanation: This is the correct syntax and order for the main method.
Q23
Which keyword is used to declare a constant in Java?
  • A static
  • B constant
  • C Explanation: The final keyword prevents modification of a variable.
  • D immutable
Answer: Option C
Explanation: The final keyword prevents modification of a variable.
Q24
Which of the following is a valid Java comment?
  • A ## Comment
  • B <!-- Comment -->
  • C Explanation: // is used for single-line comments in Java.
  • D ** Comment **
Answer: Option C
Explanation: // is used for single-line comments in Java.
Q25
What is the default value of an object reference variable?
  • A 0
  • B empty
  • C Explanation: Reference variables default to null.
  • D undefined
Answer: Option C
Explanation: Reference variables default to null.
Q26
Which keyword is used to create an object in Java?
  • A create
  • B Explanation: The new keyword allocates memory for an object.
  • C object
  • D instance
Answer: Option B
Explanation: The new keyword allocates memory for an object.
Q27
Which operator is used for equality comparison in Java?
  • A =
  • B Explanation: == compares primitive values for equality.
  • C !=
  • D equals
Answer: Option B
Explanation: == compares primitive values for equality.
Q28
Which of the following is NOT an access modifier in Java?
  • A public
  • B protected
  • C private
  • D Explanation: Java does not support the internal access modifier.
Answer: Option D
Explanation: Java does not support the internal access modifier.
Q29
Which package is automatically imported in every Java program?
  • A java.util
  • B java.io
  • C Explanation: The java.lang package is imported by default.
  • D java.net
Answer: Option C
Explanation: The java.lang package is imported by default.
Q30
Which keyword is used for inheritance in Java?
  • A implements
  • B inherits
  • C Explanation: The extends keyword allows a class to inherit another class.
  • D super
Answer: Option C
Explanation: The extends keyword allows a class to inherit another class.
Questions and Answers for Competitive Exams Various Entrance Test