Interfaces


  1. What is the output of below snippet?
    try (InputStream is = ...) 
    {
    // do stuff with is...
    }
    catch (IOException e)
    {
    // handle exception
    }











  1. 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.


  1. What is the difference between AutoCloseable and Closeable?











  1. 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.



  1. What is the use of Flushable interface?











  1. 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.


  1. Which version of java added Flushable interface?









  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Flushable and Closeable interface are added in java SE 5.



  1. Does close() implicitly flush() the stream.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    close() closes the stream but it flushes it first.