1Q)What output is displayed by the following program?
import java.io.*;
public class TestIOApp {
public static void main(Strin args[]) throws IOException {
RandomAccessFile file = new RandomAccessFile("test.txt", "rw");
file.writeBoolean(true);
file.writeInt(123456);
file.writeInt(7890);
file.writeLong(1000000);
file.writeInt(777);
file.writeFloat(.0001f);
file.seek(5);
System.out.println(file.readInt());
file.close();
}
}
A)123456
B)7890
C)1000000
D)777
E).0001
The answer is B)How? Please anybody explain it.
2Q)What is the value displayed by the following program?
class Question {
static boolean sideEffect(boolean b) {
System.out.print("side effect");
return b;
}
public static void main(
String[] args) {
boolean b1 = true;
boolean b2 = false;
if(b2 & sideEffect(b1)) System.out.println(1);
else if(b1 | sideEffect(b2)) System.out.println(2);
}
}
A)1
B)2
C)side effect 1
D)side effect 2
E)side effect side effect 1
F)side effect side effect 2
The answer is F). How? Please anybody explain it.