Font size
WorksheetsSE1 lý thuyết
Total questions: 150
Worksheet time: 1hrs 15mins
Which of the following is something an abstract class CANNOT do?
Contain abstract methods
Contain concrete methods
Be instantiated directly using new
Have a constructor
Which statement is true about an abstract method?
It cannot be overridden
It must be declared final
It has no method body
It must have a full method body
What can an interface NOT contain?
Method signatures
Constructors
public static final constants
Abstract methods
How many interfaces can a class implement in Java?
Maximum 2
Exactly 1
Unlimited number
0 or 1
Which keyword is used to inherit from an abstract class?
override
implements
extends
super
Which keyword is used to implement an interface?
override
extends
inherit
implements
According to the pre-condition rule, a subclass must:
Have stricter input requirements
Have no constraints
Reject more inputs than the superclass
Have weaker or equal input requirements
According to the post-condition rule, a subclass must:
Return a wider range of outputs
Return weaker guarantees
Return stronger or equal guarantees
Not change the output
Which of the following is true about polymorphism?
It only works with interfaces
It requires final methods
It increases reuse and maintainability
It is static binding
When should you use an abstract class?
When unrelated classes need the same behavior
When classes share common characteristics (IS-A)
When multiple inheritance of classes is needed
When no shared logic is needed
Which statement best distinguishes an abstract class from an interface in an object‑oriented language?
Interfaces can have state and constructors; abstract classes cannot
Abstract classes allow constructors and fields; interfaces do not
Interfaces support inheritance of implementation; abstract classes never do
Abstract classes only declare method signatures; interfaces provide bodies
When should you prefer an abstract class over an interface?
When classes share common properties and behavior
When unrelated classes follow the same contract
When you need multiple inheritance of implementations
When no shared logic exists across classes
When is an interface the better choice?
When classes share state and concrete methods
When subclassing is required to reuse implementation
When you must restrict instantiation with constructors
When unrelated classes must expose the same behavior
According to the pre‑condition rule for method overriding, a subclass must:
Have no constraints on input at all
Accept weaker or equal input restrictions
Reject a broader set of inputs than the superclass
Demand stricter input requirements than the superclass
According to the post‑condition rule for method overriding, a subclass must:
Provide stronger or equal output guarantees
Return weaker guarantees than the superclass
Return a wider range of outputs than before
Avoid changing the method’s observable effects
What is polymorphism in object‑oriented programming?
Sharing fields across subclasses automatically
Static binding of method calls at compile time
A single class owning many unrelated interfaces
Different objects respond differently to the same method call
Why do interfaces enable polymorphism effectively?
Multiple classes can implement the same contract type
They require final methods for consistent behavior
They enforce constructors for uniform instantiation
They prevent method overriding across implementations
Why can’t an abstract class be instantiated directly?
It must be declared final to be used
It lacks any fields or constructors by design
It contains abstract methods without implementation
It always requires multiple inheritance
Choose the correct declaration of an abstract class with one abstract method makeSound().
abstract class Animal { void makeSound() {} }
class Animal { abstract void makeSound() {} }
interface Animal { abstract void makeSound(); }
abstract class Animal { abstract void makeSound(); }
Select the correct interface declaration with a single method fly().
interface Flyable { void fly(); }
abstract interface Flyable { void fly() {} }
class Flyable { void fly(); }
interface Flyable { final void fly(); }
Which statement about polymorphism is false?
It increases reuse and maintainability of code
It only works when using interfaces
Method calls can dispatch to different implementations
Different types can be treated uniformly by a common type
Identify the correct application of the pre‑condition rule when overriding validate(input).
Subclass accepts more input cases than superclass
Subclass requires stricter input than superclass
Subclass rejects all inputs superclass accepts
Subclass ignores input and throws an error
Identify the correct application of the post‑condition rule when overriding compute().
Subclass removes all guarantees on outputs
Subclass returns unrelated data type arbitrarily
Subclass returns guarantees at least as strong
Subclass weakens output guarantees overall
Which situation most strongly suggests using an interface over an abstract class?
Airplane, Bird, and Drone must all be flyable
Cat and Dog share fields and a base eat() method
Shapes share area() logic and state
A family of sensors needs common calibration code
Select the best reason to declare a method abstract in a base class.
You need subclasses to provide specific implementations
You need to store shared state for all instances
You must allow direct instantiation of the base
You want to prevent overriding in subclasses
Which option correctly describes method overriding?
Superclass replaces a method of its subclass at runtime
Subclass adds a new unrelated method to the type
Subclass hides a field with the same name as superclass
Subclass provides its own implementation for an inherited signature
In an abstract class Animal with abstract makeSound() and concrete eat(), what must subclasses Dog and Cat do regarding makeSound()?
Override eat() instead of makeSound()
Use interface default method for makeSound()
Provide concrete implementations of makeSound()
Declare makeSound() as final and unused
Given: Animal a = new Dog("Rex"); a.makeSound(); a.eat(); Which concept allows a to call Dog’s makeSound() while typed as Animal?
Polymorphism via dynamic dispatch
Encapsulation through private fields
Inheritance through constructor chaining
Abstraction using abstract data types
You create an interface Flyable with method fly(). Classes Bird, Airplane, Superman implement it. What must each class provide at minimum?
A protected fly() with no body
An abstract fly() declaration
A concrete fly() implementation
A static fly() utility method
Which statement best describes interface implementation messages for Bird, Airplane, Superman?
All must be identical across classes
Each should differ while satisfying Flyable
Messages depend on abstract class Animal
Only Bird needs a unique message
Given interface Drawable { void draw(); } and classes Circle, Square, Triangle implement it. What collection type enables polymorphic iteration calling draw()?
Map from Class to Method
ArrayList of String names
Array of Object references
Drawable[] array of shapes
In a loop over Drawable[] shapes, what happens when draw() is called on each element?
The concrete class’s draw() executes
Only Circle implements draw() correctly
The interface’s default draw() runs
A runtime error occurs for interfaces
Pre-condition in method add(int a) ensures a > 2. What is the primary purpose of this pre-condition?
Describe output formatting rules
Optimize memory allocation strategy
Prevent overriding in subclasses entirely
Guarantee caller meets input constraints
Post-condition in add returns a + 5 with result > 7. What does the post-condition guarantee?
The object state resets after execution
The parameter becomes immutable forever
The returned value satisfies a constraint
The method will never throw exceptions
A subclass BetterCalculator accepts weaker input (a > 0) and stronger output (result > 10). Which correctness principle is demonstrated?
Liskov substitution with contract strengthening
Open/Closed principle violating inheritance
Singleton pattern ensuring one instance
Dependency inversion through interfaces
Interfaces Runnable { void run(); } and Jumpable { void jump(); }. A class Athlete implements both. What must Athlete include?
A single method combining both actions
Protected constructors for each interface
Two abstract method stubs only
Concrete run() and jump() methods
Which statement is TRUE about checked exceptions?
They indicate programming logic errors
They inherit from RuntimeException hierarchy
They must be handled or declared using throws
They occur only at runtime
Which of the following is an unchecked exception?
IOException in file handling
FileNotFoundException thrown by IO
ClassNotFoundException from ClassLoader
NullPointerException due to null dereference
Unchecked exceptions are subclasses of which type?
RuntimeException specific hierarchy
IOException in IO package
Throwable root class of errors
Exception in general hierarchy
When designing an abstract Animal, which member is valid in an abstract class but not in an interface (pre-Java 8)?
Multiple inheritance of implementation
Private instance fields with state
Abstract methods without bodies
Public constants defined inline
A method overriding add(int a) in BetterCalculator changes pre-condition from a > 2 to a > 0. Which risk must be avoided to preserve substitutability?
Ignoring super.add call in implementation
Using more parameters than superclass
Throwing fewer exceptions than superclass
Making output constraint weaker than superclass
Which statement is TRUE about checked exceptions?
They represent programming logic errors
They must be handled or declared using throws
They inherit from RuntimeException
They occur only at runtime
Which of the following is an unchecked exception?
NullPointerException
ClassNotFoundException
IOException
FileNotFoundException
Unchecked exceptions are subclasses of:
Exception
Throwable
RuntimeException
IOException
Which action does the throw keyword perform?
Declares that a method might throw an exception
Catches an exception
Throws an exception object inside a method
Converts checked exception to unchecked exception
Which action does the throws keyword perform?
Declares that the method may throw an exception
Immediately terminates the method
Logs an exception
Creates an exception object
A compile-time error occurs during:
Logical operations
Syntax and type checking
JVM interpretation
Program execution
A runtime error occurs during:
Compiling
Writing code
Program execution
IDE formatting
Which exception category typically represents external/environment errors?
Logic exceptions
Unchecked
RuntimeException
Checked
What is “masking” in exception handling?
Reflecting the original error
Logging the error then rethrowing
Hiding an exception and throwing a more meaningful one
Printing the stack trace only
What does “reflecting” an exception mean?
Logging and swallowing the error
Re-throwing the original exception to the caller
Converting the exception into another exception
Preventing error propagation
What is the difference between checked and unchecked exceptions? Provide a concise explanation.
Checked must be handled at compile time; unchecked occur at runtime
Checked occur at runtime; unchecked must be declared
Checked are logic errors; unchecked are syntax errors
Checked are from RuntimeException; unchecked are from Exception
Select two examples of checked exceptions.
IOException and FileNotFoundException
NullPointerException and ArithmeticException
OutOfMemoryError and StackOverflowError
IllegalArgumentException and NumberFormatException
Select two examples of unchecked exceptions.
IOException and FileNotFoundException
NullPointerException and ArithmeticException
ClassNotFoundException and SQLException
EOFException and InterruptedException
What is the primary purpose of the throw keyword in a method body?
Declare potential exceptions to callers
Create an exception class
Convert checked to unchecked exceptions
Throw a specific exception instance
What is the primary purpose of the throws keyword in a method signature?
Handle exceptions internally
Declare that the method may throw exceptions
Log exceptions to a file
Terminate execution on error
Which action best describes logging an exception?
Terminating the JVM on error
Transforming it into a custom exception
Recording the error to file or console
Suppressing the stack trace
Which scenario most clearly involves exception masking?
Ignoring the catch block entirely
Catching and rethrowing the same exception
Printing stack trace without rethrowing
Wrapping IOException into a DomainException with context
Which scenario most clearly involves exception reflecting?
Catching and rethrowing the same exception
Wrapping a NullPointerException into IllegalStateException
Logging only and continuing
Suppressing the error with default values
During which phase would a missing checked exception declaration be detected?
Compile-time checking
Runtime execution
JVM bytecode loading
Unit testing
Which pairing correctly matches keyword to role in Java exceptions?
throw: create object, throws: declare
throw: log error, throws: terminate
throw: catch error, throws: convert
throw: declare, throws: create
Which statement best distinguishes compile-time errors from runtime errors?
Compile-time only logic mistakes, runtime only syntax issues
Compile-time before execution, runtime during execution
Compile-time during execution, runtime before execution
Both occur only after deployment, not during tests
To create a custom checked exception in Java, which class should you extend?
RuntimeException class
Exception class directly
Error superclass
Throwable interface
To create a custom unchecked exception in Java, which base type is appropriate?
Extend RuntimeException
Extend Exception
Implement AutoCloseable
Extend IOException
In a method signature, what does the throws keyword indicate?
Method may propagate a checked exception
Method will catch the exception internally
Method masks exceptions with a wrapper
Method creates a new exception object
Inside a method body, what is the purpose of the throw statement?
Convert checked exceptions to unchecked
Log and ignore the exception silently
Declare potential exceptions to callers
Immediately trigger a specific exception
Given public int divideBy(int x) throws NonPositiveException, when should NonPositiveException be thrown?
When x is less than or equal to zero
When integer division has no remainder
When x equals one hundred exactly
When x is greater than zero only
Which snippet correctly demonstrates throw vs throws for a file read method?
Method declares nothing, body logs without throwing
Method declares throws RuntimeException, body catches IOException
Method declares throws IOException, body throws new IOException
Method declares throws Exception, body returns silently
Which exception is typically unchecked in Java arithmetic operations?
SQLException
IOException
ArithmeticException
FileNotFoundException
A method that reads a file must handle which requirement regarding exceptions?
Declare throws IOException or catch it
Declare throws ArithmeticException always
Never use try–catch inside it
Always convert to RuntimeException
When masking an exception, what is the usual outcome?
Suppress and ignore the original fully
Log only without throwing anything
Convert checked to unrelated runtime silently
Wrap original inside a custom domain exception
In the masking example, which original exception is wrapped by DataAccessException?
SQLException from connectDatabase
ArithmeticException from division
NullPointerException from parsing
IOException from readConfigFile
Reflecting an exception means what in practice?
Log and convert to return code
Catch and rethrow the same exception
Replace with a different exception
Swallow and continue execution
In loadConfig(), reflecting occurs in the catch block by doing which action?
throw e to propagate unmodified
return silently without throw
throw new RuntimeException(e)
e.printStackTrace only
Which is a correct logging technique in a catch block for ArithmeticException?
Always mask with DataAccessException
Use throws to declare logging
Reassign e to a new variable name
Call e.printStackTrace to record details
Which choice best describes a checked exception?
Thrown exclusively by JVM internals
Never needs to be handled by callers
Occurs only due to programmer mistakes
Must be declared or caught at compile time
Which choice best describes an unchecked exception?
Always originates from I/O operations only
Subclass of Exception requiring throws in signatures
Subclass of RuntimeException not required to declare
Must be wrapped before propagation always
When calling two methods, one throwing IOException and one dividing numbers, which should you handle explicitly?
Handle the unchecked ArithmeticException only
Handle the checked IOException explicitly
Handle both with identical declarations
Handle neither to avoid overhead
What is a sound reason to mask a low-level SQLException with DataAccessException?
Convert it into compile-time syntax warnings
Force callers to ignore database failures
Provide domain-specific context while preserving cause
Hide all details to avoid any debugging
In Java, what is the primary role of a finally block in a try-catch-finally construct?
It handles unchecked exceptions only
It executes after try and catch always
It rethrows the current exception automatically
It prevents exceptions from propagating
Which order of catch blocks prevents unreachable code when handling exceptions FileNotFoundException, NumberFormatException, and Exception?
NumberFormatException, FileNotFoundException, Exception
Exception, NumberFormatException, FileNotFoundException
NumberFormatException, Exception, FileNotFoundException
FileNotFoundException, NumberFormatException, Exception
A method C throws a checked exception that is caught in method A after calls A → B → C. Which statement best describes this flow?
Exception cannot cross method boundaries
Exception is swallowed in B automatically
Exception propagates from C to A through B
Exception must be converted to RuntimeException
You must create InvalidAgeException extending RuntimeException and throw it when age < 0 or age > 150. Why extend RuntimeException here?
To force callers to declare throws clause
To enable multiple catch blocks to work
To avoid compile-time checking for this rule
To guarantee logging occurs automatically
In a multi-catch scenario reading a file, parsing an integer, then dividing, which exception most likely indicates the file path does not exist?
ArithmeticException from division by zero
NumberFormatException from parse failure
FileNotFoundException from missing file
IOException from network timeout
When would a NumberFormatException be the correct catch target in the sequence read → parse → divide?
When the file handle closes early
When the file is missing entirely
When the parsed text is non-numeric
When the division result is infinity
Given try { read file; parse number; divide result; } with separate catches for FileNotFoundException, NumberFormatException, and Exception, what is the purpose of the final catch(Exception e)?
Convert checked exceptions to errors
Handle any exceptions not matched earlier
Handle only unchecked exceptions generically
Prevent finally block from executing
Which statement about finally blocks is accurate regarding control flow with return statements inside try or catch?
Finally is skipped if try returns
Finally executes even if try returns
Finally runs only when an exception occurs
Finally runs only if catch executes
Design a method that validates age using InvalidAgeException. Which approach correctly signals invalid input?
Return -1 to indicate invalid age
Log a warning and continue silently
Throw new InvalidAgeException("age out of range")
Catch and ignore NumberFormatException
In the chain A → B → C, C throws IOException and B does not catch it. What must be true in method signatures for compilation?
Neither needs throws because IOException is unchecked
Only B must declare throws IOException
Only A must declare throws IOException
A and B must declare throws IOException
What is the safest placement of a general catch(Exception e) relative to specific exceptions in a list of catch blocks?
First, before all specific catches
Anywhere, order does not matter
Last, after all specific catches
Between two specific catches only
A student writes code with try-catch-finally where finally closes a file stream. Why is this practice recommended?
Finally guarantees resource cleanup
Finally prevents all runtime errors
Finally avoids checked exceptions entirely
Finally improves parsing accuracy
What is the purpose of the Iterable interface?
It prints elements automatically
It provides a way to produce an Iterator
It allows modifications to internal structure
It sorts the collection
Which method enables foreach iteration?
iterator()
hasNext()
next()
forEach()
What does the Iterator interface NOT guarantee?
Ability to check if more elements exist
Ability to restart iteration
Order of traversal
Ability to remove elements
What requirement must a class meet to use foreach loops?
It must extend List
It must implement Iterator
It must implement Iterable
It must implement Collection
What happens when next() is called but hasNext() is false?
It resets the iterator
It returns null
Nothing happens
It throws NoSuchElementException
Which statement about remove() is TRUE?
It must always be supported
It is optional and may throw UnsupportedOperationException
It clears the collection
It removes all elements
Which of the following standard collections guarantee iteration order?
TreeSet
LinkedHashSet
HashSet
HashMap
Which iterator implementation supports fail-fast behavior?
Iterators using arrays
None of them
All custom iterators
java.util collection iterators (ArrayList, HashMap)
What pattern is applied when hiding internal structure behind an iterator?
Factory Pattern
Representation Exposure Prevention (REP)
Builder Pattern
Singleton Pattern
Why are iterators commonly implemented as inner classes?
They must be public
They need direct access to private fields
They replace constructors
They require static keyword
Which is TRUE about generic iterators?
They force runtime casting of elements
They cannot use type parameters
They enable compile-time type safety
They require raw types for collections
In a fail-fast iterator, what typically triggers ConcurrentModificationException?
Calling next() repeatedly
Updating the collection structurally during iteration
Invoking hasNext() on an empty iterator
Creating two iterators on one collection
Which method combination forms the minimal Iterator contract?
hasNext(), next(), remove()
size(), get(), set()
stream(), collect(), map()
iterator(), forEach(), remove()
Which statement best describes foreach over an Iterable?
It guarantees constant-time traversal
It restarts iteration after completion
It copies elements before iteration
It uses the object's iterator() method implicitly
What is a safe way to remove elements during iteration over a List?
Create a new list and swap references
Use the iterator's remove() after calling next()
Modify the list directly via list.remove(index)
Call clear() before iterating
Which operation happens in a mapping iterator?
Filtering data
Removing duplicates
Transforming input to output
Sorting elements
What is the output type of an Iterable
Any type
Object
Iterator
T
A reverse iterator changes what behavior?
Iterates from end to start
Changes hasNext behavior
Only changes next behavior
Merges two collections
Which iterator is used in Java streams under the hood?
Iterable
Iterator
Spliterator
Scanner
Mapping iterators support which data scope?
Only for List collections
Multiple data types
Only String type
Not for custom classes
Which statement best describes fail-fast behavior in Java iterators?
Iterator restarts from the beginning after any modification
Iterator locks the collection to prevent any concurrent changes
Iterator silently skips modified elements during traversal
Iterator throws ConcurrentModificationException on structural change
When should a custom collection implement Iterable?
To guarantee thread-safe iteration in all cases
To support bidirectional iteration by default
To allow random indexing for quicker access
To enable foreach iteration without exposing internals
What is the core difference between Iterable and Iterator?
Iterable supports remove(); Iterator exposes iterator()
Iterable defines iterator(); Iterator performs traversal
Iterable provides hasNext(); Iterator provides next()
Iterable allows structural changes; Iterator disallows them
Why must next() throw NoSuchElementException when no elements remain?
To indicate concurrent modification occurred
To warn that remove() cannot be used anymore
To signal invalid access beyond iteration end
To notify the iterator was reset to the start
Why does Java not support resetting an iterator to the beginning?
Iterators are always immutable objects by contract
Reset requires random access which lists cannot provide
Resetting violates the fail-fast behavior guarantee
Iterator is designed for forward-only simple traversal
What is a benefit of implementing an inner iterator class inside a collection?
Share iterators safely across multiple threads
Access private outer fields without exposing them
Avoid the need for hasNext() and next() methods
Enable bidirectional iteration automatically
What typically happens if you structurally modify a List during a foreach loop?
The modification is silently ignored
The iterator resets to the first element
The loop continues but skips new elements
A ConcurrentModificationException is thrown
Why should internal storage (e.g., internalList) in custom collections be private?
To enable automatic synchronization on the list
To improve garbage collection performance significantly
To ensure faster iteration over elements always
To prevent representation exposure and protect invariants
What is the difference between iterator.remove() and external structural modifications?
External changes are ignored by fail-fast iterators
remove() always throws NoSuchElementException
Both operations are treated as safe during iteration
remove() is safe within iterator; external changes trigger fail-fast
Why might one use an iterator instead of index-based access?
Some collections like sets do not support indexing
Iterators guarantee O(1) access for all elements
Iterators automatically sort elements during traversal
Indexing always causes fail-fast exceptions
True or False: All Java collections implement Iterable.
True
False
Only Sets
Only Lists
True or False: Iterator.remove() is always available.
True — available for Lists only
True — required by the interface
False — remove() is optional
False — method is deprecated
True or False: You can use multiple iterators on the same collection simultaneously.
False — only one iterator is allowed
True — safe even during structural changes
True — but modifications may cause fail-fast
False — foreach prevents additional iterators
True or False: foreach uses Iterator internally.
True
Only for Lists
Only for arrays
False
True or False: Iterable
True — Iterable must define next()
False — Iterator implements next()
True — next() in foreach is mandatory
False — next() is provided by List
True or False: Custom iterators can return values of a different type from internal storage.
False — violates type erasure
True — only with arrays
False — must match storage type
True — via mapping iterator
Which situation most likely triggers ConcurrentModificationException during iteration?
Reading elements with next() repeatedly
Adding to the underlying collection externally
Calling iterator.remove() when hasNext() is true
Creating a second iterator without using it
Which design goal is supported by keeping internal representation private in custom collections?
Ensuring constant-time iteration
Maintaining class invariants and REP
Providing thread-safe iteration by default
Enabling automatic bidirectional traversal
An iterator is consumed after full traversal. Choose the correct statement.
True for standard single-pass iterators
False unless collection is immutable
True only for primitive arrays
False for all Java iterators
Iterators guarantee sorting. Select the correct claim.
False, order depends on source
False, unless using TreeSet
True, they always sort ascending
True, if elements are comparable
What does the code print? List
true because third element remains
false because iterator resets
false because hasNext checks size only
true because iterators loop forever
What happens? List
Silently restarts iteration
Returns "A" then continues
Returns "B" without error
Throws ConcurrentModificationException
Foreach desugaring: for (String s : list) { ... } becomes which core pattern?
Use iterator with hasNext and next
Index loop over list.size()
Recursion over sublists
Stream forEach terminal op
Identify the bug: if (!hasNext) { throw new NoSuchElementException(); }
Negation should be removed
Bracket placement is incorrect
Exception type should be IllegalStateException
hasNext is a method, call hasNext()
What happens? Iterator
IllegalStateException because next not called
ConcurrentModificationException immediately
Removes first element by default
NoSuchElementException on empty list
Design IntRange implements Iterable
end and step size
only start value
start and end boundaries
start, end, and capacity
ReverseList implements Iterable
From last element to first
From first element to last
Interleaving even then odd
Random access by hash
EvenIterator implements Iterator
Return them unchanged
Skip them during traversal
Convert them to zero
Throw UnsupportedOperationException
MergedIterator
Sequentially traverse first then second
Randomly mix from both
Sort combined elements ascending
Deduplicate equal elements only
MapperIterator
Only a collection source
Stream and collector
Base iterator and mapping function
Comparator and predicate
A custom collection with inner iterator should minimally include which components?
Tree root, leaves, balancing logic
File store, cache layer, thread pool
Internal list, custom iterator, foreach support
Graph nodes, edges, traversal cost
CharIterable("ABC") should produce which sequence when iterated?
'A' then null then 'C'
'C', 'B', 'A' reversed
'A', 'B', 'C' in order
"ABC" as one token
Safe removal iterator design: which rule ensures legality of remove()?
Call next() before remove()
Never call next() during removal
Call remove() twice consecutively
Call hasNext() after remove()
Which statement best describes hasNext() in typical iterators?
Consumes the next element
Sorts remaining elements
Checks if a next element exists
Resets iterator position
When modifying a list during iteration with its iterator, why might ConcurrentModificationException occur?
Calling next on empty list
Using immutable collections
Structural change outside iterator
Reading through hasNext only
Which iterator variant transforms elements while iterating, producing a different type?
MapperIterator
ReverseList iterator
EvenIterator for filtering
MergedIterator
What is the primary purpose of assertions in Java?
Replace all error handling
Handle runtime exceptions
Validate user input
Check internal assumptions during development
Which keyword is used to write an assertion?
verify
ensure
check
assert
What happens if an assertion fails?
Program continues normally
The JVM turns off assertions
AssertionError is thrown
The compiler stops
