Interfaces
- What is the output of below snippet?
try (InputStream is = ...)
{
// do stuff with is...
}
catch (IOException e)
{
// handle exception
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Using java 7 and above, AutoCloseable objects can be opened in the try-block (within the ()) and will be automatically closed instead of using the finally block.
- What is the difference between AutoCloseable and Closeable?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Closeable extends AutoCloseable and both are interfaces. Closeable throws IOException and AutoCloseable throws Exception.
- What is the use of Flushable interface?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Flushable interface provides flush() method which Flushes this stream by writing any buffered output to the underlying stream.
- Which version of java added Flushable interface?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Flushable and Closeable interface are added in java SE 5.
- Does close() implicitly flush() the stream.
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
close() closes the stream but it flushes it first.