OOPS.................

Thursday, March 26, 2009

what is the out put of the following code........

import java.util.*;
import java.io.*;
public class SerialPeople{
Vector v = new Vector();
public static void main(String argv[]){
SerialPeople p = new SerialPeople();
p.write();
p.read();
}
public void write(){
v.add("tim");
v.add("matthew");
v.add("sarah");
try{
FileOutputStream out = new FileOutputStream("people.ob");
ObjectOutputStream s = new ObjectOutputStream(out);
s.writeObject(v);
s.flush();
}catch(IOException ioe){
System.out.println(ioe.getMessage());
}
}
public void read(){
Vector v= new Vector();
try{
FileInputStream in = new FileInputStream("people.ob");
ObjectInputStream fin = new ObjectInputStream(in);
v= (Vector)fin.readObject();
}catch(Exception e){
System.out.println(e.getMessage());
}
for(Object name : v){
System.out.println(name);
}
}

}

Answers:>>>>>>>>>


1:Compile time error, malformed for loop
2:Compile time error writeObject takes an object not a Vector type
3:Compilation and output of of the memory address of each element of the vector v
4:Compilation and output of tim matthew sarah at runtime