|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.250 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|
SCJP 5.0 Mock Exam -2
4) What will be the output of the following program?
package scjp5_0.chap03;
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());
}
}
- The program will raise a run-time exception telling that it is not possible to skip bytes in the middle of a reading operation.
- The program will output 'd'.
- The program will output 'e'.
- The program will output 'g'.
Answer:
4) d.
The read() operations will make the pointer to point to 'b'. Then the pointer is made to proceed to the next four characters by calling the skip() method. Now, the current pointer is pointing to the character 'f'. So, the next read() operation will return 'g'.
|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.250 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|
|