0% found this document useful (0 votes)
7 views19 pages

Java Reviewer

The document provides a comprehensive overview of Java concepts, including abstraction, method overloading, data structures, algorithms, collections, and exception handling. It consists of multiple-choice questions and answers that cover fundamental principles and functionalities within Java programming. Key topics include the definition of abstraction, characteristics of abstract classes, method overloading rules, data structure types, and exception management in Java.

Uploaded by

erosparabas
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)
7 views19 pages

Java Reviewer

The document provides a comprehensive overview of Java concepts, including abstraction, method overloading, data structures, algorithms, collections, and exception handling. It consists of multiple-choice questions and answers that cover fundamental principles and functionalities within Java programming. Key topics include the definition of abstraction, characteristics of abstract classes, method overloading rules, data structure types, and exception management in Java.

Uploaded by

erosparabas
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

JAVA ABSTRACTION (1–15)

1. What is abstraction in Java?


A. Hiding data
B. Showing all details
C. Hiding implementation details and showing functionality
D. Deleting unused methods

Answer: C

2. Which keyword is used to create an abstract class?


A. interface
B. abstract
C. extends
D. implements

Answer: B

3. An abstract method has:


A. A method body
B. No method body
C. Private access only
D. Static keyword

Answer: B

4. Which of the following is TRUE about abstract classes?


A. They cannot have constructors
B. They cannot have variables
C. They can have abstract and non-abstract methods
D. They cannot be inherited

Answer: C

5. How do you access an abstract class?


A. By creating an object
B. By extending it
C. By importing it
D. By copying it

Answer: B

6. Which keyword is used to inherit an abstract class?


A. implements
B. inherit
C. extends
D. super

Answer: C

7. An abstract class can have:


A. Only abstract methods
B. Only non-abstract methods
C. Both abstract and non-abstract methods
D. No methods

Answer: C

8. What happens if a class does not implement all abstract methods?


A. Program runs normally
B. Compiler error
C. Runtime error
D. Logical error

Answer: B

9. Which access modifier is NOT allowed for abstract methods?


A. public
B. protected
C. private
D. default

Answer: C

10. Can abstract classes have constructors?


A. Yes
B. No
C. Only static
D. Only final

Answer: A

11. Why is abstraction used?


A. To increase memory usage
B. To reduce complexity
C. To slow execution
D. To duplicate code

Answer: B
12. Which is more abstract?
A. Class
B. Object
C. Interface
D. Method

Answer: C

13. Abstract classes are mainly used for:


A. Data storage
B. Code duplication
C. Security and structure
D. File handling

Answer: C

14. Can an abstract class be final?


A. Yes
B. No
C. Sometimes
D. Only in Java 8

Answer: B

15. What symbol indicates an abstract method has no body?


A. {}
B. ()
C. ;
D. []

Answer: C

METHOD OVERLOADING (16–30)


16. Method overloading means:
A. Same method name, different parameters
B. Same method name, same parameters
C. Different method name, same parameters
D. Multiple classes

Answer: A

17. Which is NOT used for method overloading?


A. Different number of parameters
B. Different data types
C. Different return type only
D. Different parameter order

Answer: C

18. Method overloading happens at:


A. Runtime
B. Compile time
C. Execution time
D. Debug time

Answer: B

19. Can methods be overloaded by changing return type only?


A. Yes
B. No
C. Sometimes
D. Only in Java 8

Answer: B

20. Which is an example of overloading?


A. sum(int a), sum(int a, int b)
B. sum(int a), add(int b)
C. sum(int a), sum(int a)
D. sum(int a), sum(double a, int b, String c)

Answer: A

21. Method overloading improves:


A. Code redundancy
B. Readability
C. Memory leak
D. Errors

Answer: B

22. Which keyword is used for method overloading?


A. override
B. overload
C. none
D. extends
Answer: C

23. What happens if Java cannot determine which method to call?


A. Runtime error
B. Logical error
C. Compilation error
D. Program skips method

Answer: C

24. Overloaded methods must have:


A. Same name
B. Same parameters
C. Same return type
D. Same access modifier

Answer: A

25. Can constructors be overloaded?


A. Yes
B. No
C. Sometimes
D. Only static

Answer: A

26. Method overloading is an example of:


A. Inheritance
B. Polymorphism
C. Encapsulation
D. Abstraction

Answer: B

27. Which polymorphism is method overloading?


A. Runtime
B. Compile-time
C. Dynamic
D. Late binding

Answer: B

28. Java decides which overloaded method to use based on:


A. Method name
B. Number and type of arguments
C. Return type
D. Access modifier

Answer: B

29. Method overloading helps when:


A. Same operation with different inputs
B. Different classes
C. File handling
D. Error handling

Answer: A

30. Overloaded methods must differ in:


A. Parameters
B. Name
C. Class
D. Access level

Answer: A

JAVA DATA STRUCTURES & ALGORITHMS (31–60)


31. What is a data structure?
A. Programming language
B. Way to store and organize data
C. Loop
D. Compiler

Answer: B

32. Which is a linear data structure?


A. Tree
B. Graph
C. Stack
D. Network

Answer: C

33. Stack follows which principle?


A. FIFO
B. LIFO
C. FILO
D. Random
Answer: B

34. Queue follows which principle?


A. LIFO
B. FIFO
C. FILO
D. Random

Answer: B

35. What is an algorithm?


A. Variable
B. Step-by-step procedure
C. Data type
D. Compiler

Answer: B

36. Which data structure uses nodes?


A. Array
B. Stack
C. Linked list
D. Queue

Answer: C

37. Time complexity of linear search:


A. O(1)
B. O(log n)
C. O(n)
D. O(n²)

Answer: C

38. Which is NOT a data structure?


A. Array
B. Stack
C. Loop
D. Queue

Answer: C

39. Arrays store elements in:


A. Random memory
B. Non-contiguous memory
C. Contiguous memory
D. Disk

Answer: C

40. Best structure for frequent insertion/deletion:


A. Array
B. Linked list
C. Stack
D. Queue

Answer: B

41. Stack operations are:


A. Push & Pop
B. Add & Remove
C. Insert & Delete
D. Enqueue & Dequeue

Answer: A

42. Bubble sort is a:


A. Searching algorithm
B. Sorting algorithm
C. Graph algorithm
D. Hashing algorithm

Answer: B

43. Bubble sort compares:


A. Random elements
B. Adjacent elements
C. First and last
D. Middle elements

Answer: B

44. Worst-case time complexity of bubble sort:


A. O(n)
B. O(log n)
C. O(n²)
D. O(1)
Answer: C

45. Bubble sort is best for:


A. Large data
B. Already sorted data
C. Graphs
D. Trees

Answer: B

46. Bubble sort is called so because:


A. Uses bubbles
B. Largest values bubble up
C. Smallest sinks
D. Uses recursion

Answer: B

47. Bubble sort space complexity:


A. O(n)
B. O(n²)
C. O(1)
D. O(log n)

Answer: C

48. How many passes in worst case?


A. n
B. n − 1
C. n + 1
D. n / 2

Answer: B

49. Bubble sort is:


A. Stable
B. Unstable
C. Recursive
D. Non-comparison

Answer: A

50. Bubble sort swaps when:


A. Left < Right
B. Left > Right
C. Equal
D. Always

Answer: B

JAVA COLLECTIONS & EXCEPTIONS (51–100)


51. Java Collections Framework is in which package?
A. [Link]
B. [Link]
C. [Link]
D. [Link]

Answer: C

52. Which does NOT allow duplicates?


A. List
B. Set
C. ArrayList
D. LinkedList

Answer: B

53. Which stores key–value pairs?


A. List
B. Set
C. Map
D. Queue

Answer: C

54. Which implements dynamic array?


A. Array
B. Vector
C. ArrayList
D. Stack

Answer: C

55. Which exception occurs when dividing by zero?


A. NullPointerException
B. ArithmeticException
C. IOException
D. RuntimeException

Answer: B

56. Which is a checked exception?


A. ArithmeticException
B. NullPointerException
C. IOException
D. ArrayIndexOutOfBoundsException

Answer: C

57. Which block always executes?


A. try
B. catch
C. finally
D. throw

Answer: C

58. Keyword used to throw exception manually:


A. throws
B. catch
C. throw
D. finally

Answer: C

59. Parent class of all exceptions:


A. Error
B. Object
C. Throwable
D. ExceptionHandler

Answer: C

60. Purpose of exception handling:


A. Improve UI
B. Prevent runtime crash
C. Increase speed
D. Reduce memory

Answer: B
JAVA COLLECTIONS & JAVA EXCEPTIONS (61–100)
61. Which Java interface represents an ordered collection that allows duplicates?
A. Set
B. Map
C. List
D. Queue

Answer: C

62. Which collection does NOT maintain insertion order?


A. ArrayList
B. LinkedList
C. HashSet
D. Vector

Answer: C

63. Which class stores elements using key–value pairs?


A. ArrayList
B. HashSet
C. HashMap
D. Stack

Answer: C

64. Which Java collection allows one null key and multiple null values?
A. Hashtable
B. TreeMap
C. HashMap
D. TreeSet

Answer: C

65. Which collection automatically sorts elements?


A. HashSet
B. TreeSet
C. ArrayList
D. LinkedList

Answer: B

66. Which method is used to insert an element into a Map?


A. add()
B. insert()
C. put()
D. push()

Answer: C

67. Which method retrieves a value from a Map?


A. fetch()
B. get()
C. access()
D. retrieve()

Answer: B

68. Which Java class is synchronized by default?


A. ArrayList
B. LinkedList
C. Vector
D. HashSet

Answer: C

69. Which collection works on FIFO principle?


A. Stack
B. Queue
C. Set
D. Map

Answer: B

70. Which Java class implements the Stack data structure?


A. Stack
B. Queue
C. LinkedList
D. HashMap

Answer: A

JAVA EXCEPTIONS
71. What is an exception in Java?
A. Syntax error
B. Logical error
C. Runtime event that disrupts execution
D. Compilation warning
Answer: C

72. Which keyword is used to handle exceptions?


A. handle
B. try
C. check
D. error

Answer: B

73. Which block catches an exception?


A. try
B. throw
C. catch
D. finally

Answer: C

74. Which keyword is used to declare exceptions in a method?


A. throw
B. throws
C. try
D. catch

Answer: B

75. Which block always executes whether an exception occurs or not?


A. try
B. catch
C. finally
D. throw

Answer: C

76. Which exception occurs when dividing by zero?


A. NullPointerException
B. IOException
C. ArithmeticException
D. NumberFormatException

Answer: C

77. Which exception occurs when accessing an invalid array index?


A. IndexException
B. ArrayIndexOutOfBoundsException
C. NullPointerException
D. RuntimeException

Answer: B

78. Which exception occurs when an object reference is null?


A. IOException
B. ArithmeticException
C. NullPointerException
D. RuntimeException

Answer: C

79. Which of the following is a checked exception?


A. ArithmeticException
B. NullPointerException
C. IOException
D. ArrayIndexOutOfBoundsException

Answer: C

80. Which of the following is an unchecked exception?


A. IOException
B. SQLException
C. ArithmeticException
D. FileNotFoundException

Answer: C

81. What happens if an exception is not handled?


A. Program continues normally
B. Compiler fixes it
C. Program terminates
D. Loop repeats

Answer: C

82. Which class is the parent of all exceptions?


A. Error
B. Object
C. Throwable
D. ExceptionHandler
Answer: C

83. Which keyword is used to throw an exception manually?


A. throws
B. catch
C. throw
D. finally

Answer: C

84. Can multiple catch blocks be used in one try block?


A. Yes
B. No
C. Only one
D. Only in Java 8

Answer: A

85. Which exception occurs when input is not in correct format?


A. IOException
B. NumberFormatException
C. ArithmeticException
D. RuntimeException

Answer: B

86. Which exception occurs when a file is not found?


A. IOException
B. FileMissingException
C. FileNotFoundException
D. RuntimeException

Answer: C

87. Which block must come after try?


A. throw
B. finally only
C. catch or finally
D. throws

Answer: C

88. Which exception occurs during file handling?


A. ArithmeticException
B. IOException
C. NullPointerException
D. NumberFormatException

Answer: B

89. What is the main purpose of exception handling?


A. Increase performance
B. Prevent runtime crashes
C. Reduce memory usage
D. Improve UI

Answer: B

90. Which exception occurs when converting string to number fails?


A. IOException
B. ArithmeticException
C. NumberFormatException
D. RuntimeException

Answer: C

91. Exceptions occur at:


A. Compile time only
B. Runtime only
C. Design time
D. Coding time

Answer: B

92. Which is NOT an exception type?


A. Checked
B. Unchecked
C. Runtime
D. Logical

Answer: D

93. Which class handles arithmetic errors?


A. IOException
B. NullPointerException
C. ArithmeticException
D. RuntimeException
Answer: C

94. Can a try block exist without a catch block?


A. Yes, with finally
B. No
C. Only in Java 8
D. Only once

Answer: A

95. Which exception is thrown when accessing null object?


A. IOException
B. ArithmeticException
C. NullPointerException
D. RuntimeException

Answer: C

96. Which keyword ensures resource cleanup?


A. try
B. throw
C. finally
D. catch

Answer: C

97. Which exception occurs when array size is negative?


A. ArithmeticException
B. NegativeArraySizeException
C. NullPointerException
D. RuntimeException

Answer: B

98. Which exception occurs when thread is interrupted?


A. IOException
B. InterruptedException
C. RuntimeException
D. NullPointerException

Answer: B

99. Which exception occurs when casting fails?


A. ClassCastException
B. IOException
C. ArithmeticException
D. RuntimeException

Answer: A

100. Java exception handling improves program:


A. Speed
B. Security
C. Reliability
D. Memory usage

Answer: C

You might also like