1) Which of the following is true about Java?
a) It is a purely procedural language
b) It supports multiple inheritance
c) It compiles code into machine language directly
d) None of the Above
Answer: b) It supports multiple inheritance
2) Which keyword is used to prevent a class from being inherited?
a) abstract
b) final
c) static
d) extends
Answer: b) final
3) Which of the following is not a valid Java identifier?
a) my_variable
b) _variable
c) 2variable
d) $variable
Answer: c) 2variable
4) What is the role of the "this" keyword in Java?
a) Refers to the current instance of the class
b) Refers to the superclass
c) Refers to the parent object
d) Refers to a static method
Answer: a) Refers to the current instance of the class
5) Which collection class allows elements to be accessed using a unique key?
a) ArrayList
b) LinkedList
c) HashMap
d) HashSet
Answer: c) HashMap
6) In Java, which keyword is used to implement method overriding?
a) override
b) virtual
c) extends
d) @Override
Answer: d) @Override
7) What is the default value of an instance variable in Java if it is not initialized?
a) 0
b) null
c) Depends on the data type
d) It throws a compilation error
Answer: b) null
8) Which loop is guaranteed to execute at least once in Java?
a) while loop
b) for loop
c) do-while loop
d) enhanced for loop
Answer: c) do-while loop
9)What does the "super" keyword refer to in Java?
a) Calls the superclass constructor
b) Refers to the current instance of the class
c) Refers to the subclass
d) Calls a static method
Answer: a) Calls the superclass constructor
10) Which access modifier restricts access the least in Java?
a) private
b) protected
c) public
d) default (no modifier)
Answer: c) public
11) What is the purpose of the "static" keyword in Java?
a) It allows a method to be overridden
b) It allows access to non-static members
c) It signifies that a variable or method belongs to the class
d) It prevents inheritance of a class
Answer: c) It signifies that a variable or method belongs to the class
12) Which exception is thrown when an array is accessed with an invalid index?
a) ArrayIndexOutOfBoundsException
b) IndexOutOfBoundsException
c) ArrayException
d) InvalidArrayIndexException
Answer: a) ArrayIndexOutOfBoundsException
13) Which statement is used to exit from a loop in Java?
a) return
b) break
c) continue
d) exit
Answer: b) break
14) What is the difference between "==" and ".equals()" when comparing objects in Java?
a) They are identical and can be used interchangeably
b) "==" compares object references, while ".equals()" compares object contents
c) ".equals()" compares object references, while "==" compares object contents
d) They are both used for deep comparison of objects
Answer: b) "==" compares object references, while ".equals()" compares object contents
15) Which of the following is true about the "static" keyword in Java?
a) It can be used with local variables.
b) Static methods can access non-static members directly.
c) Static methods can be overridden in subclasses.
d) Static variables are initialized when an object is created.
Answer: b) Static methods can access non-static members directly.