What will be the output of the following program?
import java.io.*;
public class ExternalizableTest {
public static void main(String[] args) throws IOException, ClassNotFoundException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(byteArrayOutputStream);
Student hemanth = new Student();
hemanth.name = "Hemanth"; hemanth.rollNumber = 25; hemanth.section = 'C';
System.out.println("Before - " + hemanth.name + " " + hemanth.rollNumber + " " + hemanth.section);
oos.writeObject(hemanth); // LINE A
oos.close();
byte[] objectDataBytes = byteArrayOutputStream.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(objectDataBytes);
ObjectInputStream ois = new ObjectInputStream(bais);
Student hemanthRestored = (Student) ois.readObject(); // LINE B
System.out.println("After - " + hemanthRestored.name + " " + hemanthRestored.rollNumber + " " + hemanthRestored.section);
ois.close();
}
}
class Student implements Externalizable {
String name = ""; int rollNumber = 0; char section = 'A';
class Student() {}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
name = in.readUTF();
rollNumber = in.readInt();
section = in.readChar();
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeUTF(name);
out.writeInt(rollNumber);
out.writeChar(section);
}
}