Skip to content
Sharp

Engineering Interviews · interview question

How would you explain a severe bug in this code regarding resource management in an interview?

Multiple choiceHardchapter-20-curatedpremiumengineering-interviewscode-review-spotting-bugs
java
public void readFile(String fileName) {
    InputStream input = new FileInputStream(fileName);
    // process the input
}
Choose one answer
Answer and explanation

Correct answer

C. InputStream is not closed, leading to resource leaks

Why

The InputStream should be closed after use to free up system resources. Failing to do so can lead to resource leaks, eventually causing the application to run out of file handles.

Test yourself on Engineering Interviews

A free test with instant, explained results. No account needed.

Start free test
All Engineering Interviews questions →