Menu
Topics Index
...
`

Creating ObjectInputStream and ObjectOutputStream


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating ObjectInputStream and ObjectOutputStream
What is the output of the following program?
import java.io.*;
public class StoreObjectState {
    public static void main(String arg[]) {
        try {
            ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream("file.txt"));
            outputStream.writeObject(new Circle(20));
            outputStream.writeObject(new Square(15));
        } catch (Exception e) { System.out.println(e); }
        try {
            ObjectInputStream intputStream = new ObjectInputStream(new FileInputStream("file.txt"));
            ((Circle) intputStream.readObject()).draw();
            ((Square) intputStream.readObject()).draw();
        } catch (Exception e) {System.out.println(e); }
    }
}
abstract class Draw implements Serializable { public abstract void draw(); }
class Square extends Draw {
    private final int x;
    public Square(int x) {
        this.x = x;
    }
    public void draw() {
        System.out.println("Square: " + x);
    }
}
class Circle extends Draw implements Serializable {
    private final int x;
    public Circle(int x) {
        this.x = x;
    }
    public void draw() {
        System.out.println("Circle : " + x);
    }
}

A. Circle : 20
Square: 15
B. Circle : 15
Square: 20
C. Compilation Error
D. NotSerializableException
E. FileNotFoundException
Topic: Java ObjectInputStream

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans : a ,serializable interface stores the data in the order given and calls according to it

Posted by Manasa Jyothi Sree    2014-04-23 13:32:20


A.is ans.bcz serializable is implemetns and.along wit this File.txt is created in currnt directory.with some non-ascii contents.

Posted by Shabaaz Shaikz    2014-04-23 13:43:03


Congratulations Manasa Jyothi Sree. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-04-24 04:20:01


© meritcampus 2019

All Rights Reserved.

Open In App