इस लेख में हमने प्रतियोगी परीक्षाओं में सबसे ज्यादा पूछे जाने वाले Java के प्रश्नों और उत्तरों की एक सूची तैयार की है, जिसमें महत्वपूर्ण Java Programing के MCQ Questions and Answers शामिल है।
ये प्रश्न आमतौर पर SSC, CGL, CHSL, IBPS, PO, UPSC, RRB, PATWARI, STATE EXAM, RAILWAY, TET, CTET, CGTET, Hostel Warden आदि जैसे Competitive Exams में पूछे जाते है। (Multiple Choice Questions and Answers on Java)
Java MCQ
1. What is the latest version of Java as of September 2023?
a) Java 7
b) Java 8
c) Java 9
d) Java 20
Answer: d) Java 20
2. Which keyword is used to define a constant in Java?
a) const
b) final
c) static
d) constant
Answer: b) final
3. What is the difference between == and .equals() in Java for comparing objects?
a) They are the same.
b) == compares object references, .equals() compares object content.
c) == compares primitive data types, .equals() compares objects.
d) == is used for assignment, .equals() for comparison.
Answer: b) == compares object references, .equals() compares object content.
4. Which of the following data types is not supported in Java?
a) int
b) float
c) decimal
d) char
Answer: c) decimal
5. In Java, which keyword is used for inheritance?
a) extends
b) inherit
c) implements
d) interface
Answer: a) extends
6. What is the purpose of the static keyword in Java?
a) To create a new object instance.
b) To make a method or variable belong to the class rather than an instance.
c) To create a subclass.
d) To declare a constant.
Answer: b) To make a method or variable belong to the class rather than an instance.
7. Which of the following is not a valid access modifier in Java?
a) public
b) private
c) protected
d) global
Answer: d) global
8. What is the output of the following code?
int x = 5;
int y = 2;
System.out.println(x / y);
a) 2.5
b) 2
c) 2.0
d) Compilation error
Answer: b) 2
9. What is the purpose of the break statement in a Java loop?
a) To terminate the program.
b) To skip the current iteration of the loop.
c) To exit the loop and continue with the next iteration.
d) To pause the loop temporarily.
Answer: c) To exit the loop and continue with the next iteration.
10. Which class is the superclass of all other classes in Java?
a) Object
b) Superclass
c) Class
d) Base
Answer: a) Object
11. Which Java keyword is used to implement multiple inheritance?
a) multiple
b) extends
c) implements
d) inherit
Answer: c) implements
12. What is the output of the following code?
String str1 = "Hello";
String str2 = "Hello";
System.out.println(str1 == str2);
a) true
b) false
c) Compilation error
d) Runtime error
Answer: a) true
13. What is the purpose of the super keyword in Java?
a) To call a superclass constructor.
b) To call a subclass constructor.
c) To access static methods.
d) To declare a constant.
Answer: a) To call a superclass constructor.
14. What is the difference between ArrayList and LinkedList in Java?
a) ArrayList is faster for random access, while LinkedList is better for insertions and deletions.
b) ArrayList uses less memory than LinkedList.
c) LinkedList is an ordered collection, while ArrayList is not.
d) There is no difference; they are the same.
Answer: a) ArrayList is faster for random access, while LinkedList is better for insertions and deletions.
15. Which exception is thrown when an array is accessed with an invalid index?
a) IndexOutOfBoundsException
b) ArrayIndexException
c) ArrayOutOfBoundsException
d) InvalidIndexException
Answer: a) IndexOutOfBoundsException
16. What is the purpose of the try, catch, and finally blocks in exception handling?
a) To handle exceptions, catch them, and release resources in the finally block.
b) To write code that should always execute.
c) To specify which exceptions to ignore.
d) To create custom exceptions.
Answer: a) To handle exceptions, catch them, and release resources in the finally block.
17. What is the purpose of the volatile keyword in Java?
a) To declare a variable as constant.
b) To indicate that a variable may be accessed by multiple threads.
c) To make a variable immutable.
d) To create a new thread.
Answer: b) To indicate that a variable may be accessed by multiple threads.
18. Which design pattern is used to ensure a class has only one instance and provides a global point of access to it?
a) Factory Pattern
b) Singleton Pattern
c) Observer Pattern
d) Adapter Pattern
Answer: b) Singleton Pattern
19. What is the Java Virtual Machine (JVM)?
a) A software development tool.
b) A hardware component of a computer.
c) A virtualization software.
d) A runtime environment for executing Java bytecode.
Answer: d) A runtime environment for executing Java bytecode.
20. Which of the following is a marker interface in Java?
a) Serializable
b) Cloneable
c) Iterable
d) Comparable
Answer: a) Serializable
21. What is the purpose of the this keyword in Java?
a) To refer to the current instance of a class.
b) To create a new instance of a class.
c) To access a superclass method.
d) To access a static variable.
Answer: a) To refer to the current instance of a class.
22. What is the difference between an interface and an abstract class in Java?
a) An interface can have method implementations, while an abstract class cannot.
b) An abstract class can have constructor methods, while an interface cannot.
c) An interface can extend multiple other interfaces, while an abstract class can extend only one class.
d) An abstract class cannot have abstract methods, while an interface can have abstract methods.
Answer: c) An interface can extend multiple other interfaces, while an abstract class can extend only one class.
23. Which Java collection class guarantees that the elements are ordered in the sequence they were added?
a) HashSet
b) LinkedHashSet
c) TreeSet
d) HashMap
Answer: b) LinkedHashSet
24. What is the purpose of the StringBuilder class in Java?
a) To format strings.
b) To create immutable strings.
c) To create mutable strings with better performance than StringBuffer.
d) To create arrays of characters.
Answer: c) To create mutable strings with better performance than StringBuffer.
25. What is the purpose of the @Override annotation in Java?
a) To override a superclass method.
b) To declare a variable as final.
c) To specify the access level of a method.
d) To indicate that a class cannot be extended.
Answer: a) To override a superclass method.
26. What is the output of the following code?
int[] arr = {1, 2, 3, 4, 5};
for (int i : arr) {
if (i == 3) {
continue;
}
System.out.print(i + " ");
}
a) 1 2 3 4 5
b) 1 2 4 5
c) 1 2 4
d) 1 2 3
Answer: b) 1 2 4 5
27. Which keyword is used to explicitly throw an exception in Java?
a) raise
b) throw
c) exception
d) catch
Answer: b) throw
28. What is the purpose of the instanceof operator in Java?
a) To check if an object is an instance of a specific class or interface.
b) To create a new instance of a class.
c) To compare two objects for equality.
d) To check if a variable is null.
Answer: a) To check if an object is an instance of a specific class or interface.
29. What is the output of the following code?
String str = "Hello";
str.concat(" World");
System.out.println(str);
a) Hello World
b) Hello
c) World
d) Compilation error
Answer: b) Hello
30. Which data structure in Java is a Last-In-First-Out (LIFO) structure?
a) Queue
b) Stack
c) ArrayList
d) Linked List
Answer: b) Stack
31. What is a lambda expression in Java?
a) A method that has no return type.
b) A function that accepts a single argument.
c) A way to create anonymous classes.
d) A way to express instances of single-method interfaces (functional interfaces) concisely.
Answer: d) A way to express instances of single-method interfaces (functional interfaces) concisely.
32. What is the purpose of the default keyword in a Java interface?
a) To specify the default access modifier for interface methods.
b) To declare a method with a default implementation in an interface.
c) To specify the default constructor for a class.
d) To define a default value for a variable.
Answer: b) To declare a method with a default implementation in an interface.
33. Which Java feature allows a subclass to provide a specific implementation of a method that is already defined in its superclass?
a) Polymorphism
b) Inheritance
c) Encapsulation
d) Abstraction
Answer: b) Inheritance
34. What is the purpose of the transient keyword in Java?
a) To declare a variable as final.
b) To make a variable immutable.
c) To specify that a variable should not be serialized.
d) To declare a variable as static.
Answer: c) To specify that a variable should not be serialized.
35. What is the Java naming convention for constants?
a) Constants should be named using all uppercase letters with underscores.
b) Constants should be named in camelCase.
c) Constants should be named with a prefix “const_”.
d) Constants should be named with a suffix “_const”.
Answer: a) Constants should be named using all uppercase letters with underscores.
36. What is the purpose of the break statement in a switch statement in Java?
a) To exit the switch statement and continue with the next case.
b) To exit the switch statement and terminate the program.
c) To skip the current case and continue with the next one.
d) To pause the switch statement temporarily.
Answer: a) To exit the switch statement and continue with the next case.
37. Which of the following is not a valid Java primitive data type?
a) boolean
b) byte
c) short
d) string
Answer: d) string
38. What is the purpose of the static block in Java?
a) To declare a static variable.
b) To define a static method.
c) To initialize static variables or perform one-time initialization tasks.
d) To declare a constant.
Answer: c) To initialize static variables or perform one-time initialization tasks.
39. What is a Java thread?
a) A process that runs independently of the main program.
b) A special type of variable.
c) A data structure used for searching in collections.
d) A type of exception.
Answer: a) A process that runs independently of the main program.
40. What is the purpose of the synchronized keyword in Java?
a) To make a method non-static.
b) To specify that a variable should not be modified.
c) To indicate that a method or block is thread-safe.
d) To declare a method as final.
Answer: c) To indicate that a method or block is thread-safe.
41. What is a Java constructor?
a) A method that is used to create objects.
b) A method that is used to destroy objects.
c) A method that is used to compare objects.
d) A method that is used to clone objects.
Answer: a) A method that is used to create objects.
42. Which of the following is not a valid Java access modifier?
a) public
b) private
c) final
d) protected
Answer: c) final
43. What is a Java package?
a) A collection of classes and interfaces.
b) A collection of variables.
c) A collection of objects.
d) A collection of loops.
Answer: a) A collection of classes and interfaces.
44. What is the purpose of the instanceof operator in Java?
a) To check if a variable is an instance of a specific class.
b) To check if a variable is null.
c) To check if a variable is a primitive data type.
d) To check if a variable is immutable.
Answer: a) To check if a variable is an instance of a specific class.
45. Which keyword is used to declare a method that can be overridden by subclasses?
a) override
b) virtual
c) abstract
d) extends
Answer: c) abstract
46. What is the purpose of the try-with-resources statement in Java?
a) To create a new resource.
b) To release resources when they are no longer needed.
c) To catch exceptions.
d) To declare a constant resource.
Answer: b) To release resources when they are no longer needed.
47. What is the purpose of the Thread.sleep() method in Java?
a) To put the current thread to sleep indefinitely.
b) To pause the execution of the current thread for a specified amount of time.
c) To terminate the current thread.
d) To wake up a sleeping thread.
Answer: b) To pause the execution of the current thread for a specified amount of time.
48. What is the output of the following code?
int x = 5;
int y = 0;
try {
System.out.println(x / y);
} catch (ArithmeticException e) {
System.out.println("Division by zero");
}
a) Division by zero
b) 0
c) Compilation error
d) Runtime error
Answer: a) Division by zero
49. What is a Java annotation?
a) A type of exception.
b) A special type of variable.
c) A metadata added to Java code to provide additional information.
d) A type of loop.
Answer: c) A metadata added to Java code to provide additional information.
50. What is the purpose of the try, catch, and finally blocks in exception handling?
a) To handle exceptions, catch them, and release resources in the finally block.
b) To write code that should always execute.
c) To specify which exceptions to ignore.
d) To create custom exceptions.
Answer: a) To handle exceptions, catch them, and release resources in the finally block.
निवेदन
उम्मीद है कि आपको यह लेख (Java – Multiple Choice Questions and Answers) जरूर पसंद आया होगा। यदि आप जावा और जावास्क्रिप्ट को लेकर अक्सर कन्फूजन में रहते हैं तो आप Java और JavaScript में अंतर लेख जरूर पढ़ें।
अगर यह Article आपके लिए उपयोगी रहा हो तो इसे अपने दोस्तों के साथ जरूर शेयर करें और आपके जो भी सवाल हों उन्हें नीचे कमेंट करके बताएं।