Menu
Question Index
...

What will be the output of the following program?

import java.io.*;

public class ExcuseMePlease {
    public static void main(String[] args) throws Exception {
        File file = File.createTempFile("excuse", "me");
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
        Excuse excuse = new Excuse();
        excuse.please.k = 50;
        oos.writeObject(excuse);
        oos.close();
        excuse.j = 75;
        excuse.please.k = 25;
        excuse.me = new Me();
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
        excuse = (Excuse) ois.readObject();
        ois.close();
        System.out.println(excuse.j + " " + excuse.me + " " + excuse.please.k);
    }
}
class Excuse implements Serializable {
    int j = 25;
    Me me = null;
    Please please = new Please();
}
class Me {
    int i;
}
class Please implements Serializable {
    transient int k;
}


25 null 0
25 null 25
75 null 0
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java ObjectInputStream

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App