Java
1. What is the default value of a boolean variable in Java?
A. true
B. false
C. null
D. 0
B. false
2. Which of the following is not a Java keyword?
A. class
B. interface
C. extends
D. println
D. println
3. What is the purpose of the "this" keyword in Java?
A. To refer to the current object
B. To refer to the superclass
C. To refer to the subclass
D. To refer to the outer class
A. To refer to the current object
5. What is the difference between "==" and ".equals()" in Java?
A. “==” checks for reference equality, “.equals()” checks for object equality
B. “==” checks for object equality, “.equals()” checks for reference equality
C. “==” checks for null, “.equals()” checks for non-null
D. “==” checks for non-null, “.equals()” checks for null
A. “==” checks for reference equality, “.equals()” checks for object equality
6. Which Java exception is thrown when an attempt is made to access an array with an index that is out of bounds?
A. ArrayIndexOutOfBoundsException
B. NullPointerException
C. ClassCastException
D. IOException
A. ArrayIndexOutOfBoundsException
7. What is the purpose of the "super" keyword in Java?
A. To refer to the current object
B. To refer to the superclass
C. To refer to the subclass
D. To refer to the outer class
B. To refer to the superclass
8. Which Java method is used to convert a string to an integer?
A. parseInt()
B. parseDouble()
C. toString()
D. toCharArray()
A. parseInt()
9. What is the difference between "break" and "continue" statements in Java?
A. “break” exits the loop, “continue” skips to the next iteration
B. “break” skips to the next iteration, “continue” exits the loop
C. “break” is used for if-else statements, “continue” is used for loops
D. “break” is used for loops, “continue” is used for if-else statements
A. “break” exits the loop, “continue” skips to the next iteration
10. Which Java class is used to handle input/output operations?
A. Scanner
B. PrintWriter
C. BufferedReader
D. All of the above
D. All of the above
11. What is the purpose of the "abstract" keyword in Java?
A. To declare an abstract class
B. To declare an interface
C. To declare a concrete class
D. To declare a method
A. To declare an abstract class
13. What is the difference between "public" and "private" access modifiers in Java?
A. “public” members are accessible only within the class, “private” members are accessible from outside the class
B. “public” members are accessible from outside the class, “private” members are accessible only within the class
C. “public” members are used for inheritance, “private” members are used for polymorphism
D. “public” members are used for polymorphism, “private” members are used for inheritance
B. “public” members are accessible from outside the class, “private” members are accessible only within the class
14. Which Java method is used to sort an array?
A. sort()
B. Arrays.sort()
C. Collections.sort()
D. All of the above
B. Arrays.sort()
15. What is the purpose of the "finally" block in Java?
A. To handle exceptions
B. To provide a default value
C. To execute code regardless of whether an exception is thrown
D. To exit the program
C. To execute code regardless of whether an exception is thrown