What interface must an object implement before it can be written to a stream as an object?
We need to implement java.io.Serializable interface which we are willing to write to a stream as an object.
Example
import java.io.Serializable;
public class Employee implements Serializable {
Integer empId;
String empName;
public Integer getEmpId() {
return empId;
}
public void setEmpId(Integer empId) {
this.empId = empId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
}
Recent Comments