Multiple choice technology programming languages

What will be the output of the following program? import java.io.ByteArrayInputStream; import java.io.InputStream; public class Ques04 { public static void main(String[] args) throws Exception{ byte buffer[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}; InputStream inputStream = new ByteArrayInputStream(buffer); inputStream.read();inputStream.read(); inputStream.skip(4); System.out.println((char)inputStream.read()); } }

  1. The program will raise a run-time exception telling that it is not possible to skip bytes in the middle of a reading operation.

  2. The program will output 'd'.

  3. The program will output 'e'.

  4. The program will output 'g'.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

read() is called twice (consumes 'a' and 'b'), skip(4) skips 'c','d','e','f'. The next read() returns 'g' (position 6, zero-indexed). The skip() method advances the stream position by 4 bytes.