0% found this document useful (0 votes)
22 views11 pages

Java MCQ Answers Full

This document contains a series of multiple choice questions and answers related to the Java programming language. It covers various topics including the history of Java, data types, operators, control structures, object-oriented programming concepts, and interfaces. Each question is followed by the correct answer, providing a comprehensive overview for learners and practitioners of Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views11 pages

Java MCQ Answers Full

This document contains a series of multiple choice questions and answers related to the Java programming language. It covers various topics including the history of Java, data types, operators, control structures, object-oriented programming concepts, and interfaces. Each question is followed by the correct answer, providing a comprehensive overview for learners and practitioners of Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Java Multiple Choice Questions and Answers

1. Who developed the Java programming language?

a) Microsoft b) Oracle c) Sun Microsystems d) Google

Answer: c) Sun Microsystems

2. In which year was the first version of Java released?

a) 1991 b) 1995 c) 1998 d) 2000

Answer: b) 1995

3. What was the original name for Java?

a) C++++ b) Oak c) Pine d) Maple

Answer: b) Oak

4. What does JVM stand for?

a) Java Version Machine b) Java Virtual Mechanism c) Java Verified Module d) Java Virtual Machine

Answer: d) Java Virtual Machine

5. Which of the following is responsible for converting bytecode into machine code?

a) JDK b) JRE c) JVM d) Java Compiler

Answer: c) JVM

6. What does JDK include?

a) Only a compiler b) Only a runtime environment c) Both a compiler and a runtime environment d) None of the

above

Answer: c) Both a compiler and a runtime environment

7. Which of the following is NOT a part of the JRE?

a) Bytecode verifier b) Classloader c) Java Compiler d) Java API classes

Answer: c) Java Compiler

8. What is the primary function of JRE?


Java Multiple Choice Questions and Answers

a) Compilation b) Debugging c) Execution d) Development

Answer: c) Execution

9. Can you run a Java program without JRE?

a) Yes b) No

Answer: b) No

10. Is JVM platform-independent?

a) Yes b) No

Answer: a) Yes

11. Which operator is used to perform bitwise "AND" operation?

a) && b) & c) | d) ||

Answer: b) &

12. What does the == operator compare in Java objects?

a) Values b) References c) Hash codes d) Fields

Answer: b) References

13. Which operator is used for logical "AND" operation?

a) && b) & c) || d) |

Answer: a) &&

14. Which of the following is a unary operator?

a) + b) - c) ! d) All of the above

Answer: d) All of the above

15. Which operator has the highest precedence?

a) + b) * c) () d) &&

Answer: c) ()
Java Multiple Choice Questions and Answers

16. What is the output of the expression true || false?

a) true b) false c) null d) 0

Answer: a) true

17. Which of the following is not a primitive data type in Java?

a) byte b) String c) double d) short

Answer: b) String

18. What is the default value of the int data type?

a) 0 b) 1 c) null d) Undefined

Answer: a) 0

19. Which of the following data types can store a floating-point number?

a) int b) byte c) double d) char

Answer: c) double

20. Which data type can store a single character?

a) String b) byte c) char d) int

Answer: c) char

21. How many bits does the long data type use?

a) 8 b) 16 c) 32 d) 64

Answer: d) 64

22. What's the main difference between int and Integer in Java?

a) No difference b) Integer can store larger values than int c) int is a primitive data type, while Integer is a class

d) int can be null, while Integer cannot

Answer: c) int is a primitive data type, while Integer is a class

23. Which loop construct in Java is best suited when the number of iterations is known?
Java Multiple Choice Questions and Answers

a) for loop b) while loop c) do-while loop d) break statement

Answer: a) for loop

24. What is the purpose of the continue statement in a loop?

a) To exit the loop immediately b) To skip the current iteration and move to the next iteration c) To terminate the

program d) To execute a specific block of code

Answer: b) To skip the current iteration and move to the next iteration

25. Which loop construct in Java is best suited when the number of iterations is unknown?

a) for loop b) while loop c) do-while loop d) none

Answer: b) while loop

26. What is the key difference between a while loop and a do-while loop in Java?

a) The syntax used to define the loop b) The number of iterations performed c) The condition check timing d)

The ability to use the break statement

Answer: c) The condition check timing

27. Which loop construct guarantees that the loop body is executed at least once?

a) for loop b) while loop c) do-while loop d) continue statement

Answer: c) do-while loop

28. What is an infinite loop?

a) A loop that executes only once b) A loop that never terminates naturally c) A loop that contains an

unreachable code block d) A loop that uses the continue statement

Answer: b) A loop that never terminates naturally

29. Which statement is used to exit a loop prematurely?

a) return statement b) continue statement c) break statement d) exit statement

Answer: c) break statement


Java Multiple Choice Questions and Answers

30. Which loop construct is best suited for iterating over an array or a collection?

a) for loop b) while loop c) do-while loop d) continue statement

Answer: a) for loop

31. How do you declare an array in Java?

a) int arrayName; b) int[] arrayName; c) int arrayName[]; d) Both b and c

Answer: d) Both b and c

32. Which method is used to get the length of an array in Java?

a) length() b) size() c) getLength() d) length

Answer: d) length

33. How do you initialize an array in Java?

a) int[] arr = (1,2,3,4,5); b) int arr = {1,2,3,4,5}; c) int[] arr = new int[]{1,2,3,4,5}; d) int arr = new int(5);

Answer: c) int[] arr = new int[]{1,2,3,4,5}

34. What happens when you try to access an array element with an index that is out of bounds?

a) It returns -1 b) It returns a null value c) It throws an exception d) It initializes a new array

Answer: c) It throws an exception

35. How can you check if two arrays are equal in Java?

a) Use the == operator b) Use the .equals() method c) Use Arrays.equals() method d) Compare each element one

by one

Answer: c) Use Arrays.equals() method

36. How do you access the fourth element of an array named numbers?

a) numbers[4]; b) numbers(3); c) numbers[3]; d) numbers.get(3);

Answer: c) numbers[3];

37. Which of the following operators is used for concatenation of two strings?
Java Multiple Choice Questions and Answers

a) + b) * c) & d) +=

Answer: a) +

38. Which of the following creates a mutable string?

a) String b) StringBuilder c) StringChar d) StringMutable

Answer: b) StringBuilder

39. In Java, strings are:

a) Primitive data types b) Immutable objects c) Mutable objects d) Arrays of characters

Answer: b) Immutable objects

40. How do you find the length of a string named 'example'?

a) example.size() b) example.length() c) example.getLength() d) example.len()

Answer: b) example.length()

41. What is the result of the expression "Java" + "Programming"?

a) JavaProgramming b) Java Programming c) Java-Programming d) JavaProgramming

Answer: a) JavaProgramming

42. Which method is used to compare two strings for equality?

a) == b) equals() c) compare() d) isEqual()

Answer: b) equals()

43. Which class can create a string that is thread-safe?

a) String b) StringBuffer c) StringBuilder d) StringSafe

Answer: b) StringBuffer

44. What is the root class for all Java classes?

a) Object b) Class c) Superclass d) Root

Answer: a) Object
Java Multiple Choice Questions and Answers

45. What is polymorphism?

a) Multiple forms b) Single form c) No form d) Static form

Answer: a) Multiple forms

46. What is encapsulation in Java?

a) The process of combining data and methods into a single unit b) The process of hiding data and methods

within a class c) The process of creating multiple instances of a class d) The process of reusing code from

existing classes

Answer: a) The process of combining data and methods into a single unit

47. What is inheritance in Java?

a) The process of creating multiple instances of a class b) The process of hiding data and methods within a

class c) The process of reusing code from existing classes d) The process of combining data and methods into

a single unit

Answer: c) The process of reusing code from existing classes

48. What is polymorphism in Java?

a) The ability of a class to inherit properties and behaviors from another class b) The process of hiding data and

methods within a class c) The process of creating multiple instances of a class d) The ability of an object to

take on many forms

Answer: d) The ability of an object to take on many forms

49. What are abstract classes in Java?

a) Classes that cannot be instantiated b) Classes that can be used as blueprints for creating objects c) Classes

that only contain abstract methods d) All of the above

Answer: a) Classes that cannot be instantiated

50. What is the purpose of the "super" keyword in Java?

a) To refer to the current object b) To invoke the superclass constructor or methods c) To create multiple
Java Multiple Choice Questions and Answers

instances of a class d) To hide data and methods within a class

Answer: b) To invoke the superclass constructor or methods

51. What is the purpose of the "this" keyword in Java?

a) To refer to the superclass b) To create multiple instances of a class c) To hide data and methods within a

class d) To refer to the current object

Answer: d) To refer to the current object

52. What is the purpose of the "final" keyword in Java?

a) To prevent the inheritance of a class b) To prevent overriding of a method c) To prevent modification of a

variable's value d) All of the above

Answer: d) All of the above

53. What is an interface in Java?

a) A class b) A data type c) A blueprint for a class d) A data structure

Answer: c) A blueprint for a class

54. Which keyword is used to implement an interface?

a) extends b) new c) interface d) implements

Answer: d) implements

55. Can an interface extend another interface in Java?

a) No b) Yes

Answer: b) Yes

56. Can an interface have a constructor?

a) Yes b) No

Answer: b) No

57. Which of the following access modifiers are implicitly applied to variables in an interface?
Java Multiple Choice Questions and Answers

a) private b) protected c) public d) default

Answer: c) public

58. Is it possible to create an instance of an interface?

a) Yes b) No

Answer: b) No

59. How many interfaces can a Java class implement?

a) None b) Only one c) Two d) As many as needed

Answer: d) As many as needed

60. Can an interface inherit from a class?

a) Yes b) No

Answer: b) No

61. Can an interface method be declared as final?

a) Yes b) No

Answer: b) No

62. In Java 9, which type of methods can be added to interfaces to share code between methods?

a) Static b) Private c) Final d) Protected

Answer: b) Private

63. An interface with no methods is known as:

a) Abstract Interface b) Marker Interface c) Empty Interface d) Functional Interface

Answer: b) Marker Interface

64. Which keyword is used to define a default method in an interface?

a) static b) default c) final d) abstract

Answer: b) default
Java Multiple Choice Questions and Answers

65. Are all methods in an interface abstract?

a) Yes b) No c) none of these d) all the above

Answer: b) No

66. Which of these can be contained in an interface?

a) Abstract methods b) Constants c) Default and static methods d) All of the above

Answer: d) All of the above

67. Which Java feature helps achieve multiple inheritance?

a) Abstract classes b) Static methods c) Interfaces d) Enums

Answer: c) Interfaces

68. What is the default access modifier of a method in an interface in Java?

a) private b) protected c) public d) None of the above

Answer: c) public

69. Why were default methods introduced in Java 8 interfaces?

a) To provide multiple inheritance b) To add utility functions c) To provide backward compatibility with older

interface versions d) For better performance

Answer: c) To provide backward compatibility with older interface versions

70. Starting from which Java version can an interface contain method implementations?

a) Java 5 b) Java 7 c) Java 8 d) Java 9

Answer: c) Java 8

71. What is the purpose of the instanceof operator?

a) Multiply instances b) Compare two object references c) Check if an object is an instance of a specific class or

interface d) To create a new instance of a class

Answer: c) Check if an object is an instance of a specific class or interface


Java Multiple Choice Questions and Answers

72. Which keyword is used to declare a class variable?

a) volatile b) transient c) static d) final

Answer: c) static

73. Which keyword is used to prevent a class from being inherited?

a) final b) abstract c) class d) extends

Answer: a) final

74. Which keyword is used to create an instance of a class?

a) new b) return c) this d) create

Answer: a) new

75. Which keyword is used to inherit the properties and methods from another class?

a) import b) package c) extends d) implements

Answer: c) extends

You might also like