Exception Handling and Java I/O Flashcards
6 cards from real SCJP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 Exception Handling and Java I/O flashcards as text
Which exception is thrown when a program attempts to cast an object to an incompatible type?
Answer: ClassCastException
`ClassCastException` is thrown at runtime when an object is cast to a class it is not an instance of.
What is the correct order of exception hierarchy evaluation in a multi-catch chain?
Answer: More specific (child) exceptions first
Catch blocks must go from most specific (child) to most general (parent); otherwise the compiler raises an error because the general block would shadow the specific one.
Which Java I/O class is used for object serialization (writing objects to a stream)?
Answer: ObjectOutputStream
`ObjectOutputStream` serializes Java objects to a byte stream; the object's class must implement `Serializable`.
What does the `transient` keyword do in the context of Java serialization?
Answer: Prevents a field from being serialized
A `transient` field is excluded from serialization and will have its default value when the object is deserialized.
Which exception does Java throw when stack memory is exhausted, typically due to infinite recursion?
Answer: StackOverflowError
`StackOverflowError` is thrown when the call stack depth exceeds the JVM limit, commonly caused by infinite or unbounded recursion.
In Java, what is the default behavior when a thread encounters an uncaught exception?
Answer: The thread terminates and the JVM continues
When a thread's `run()` method throws an uncaught exception, that thread terminates but other threads and the JVM continue running.
How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy