Menu
Question Index
...

What will be the output of the following program?s

import java.io.*;

public class ObjProgram {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        FileInputStream fis = new FileInputStream("abc.txt");
        ObjectInputStream in = new ObjectInputStream(fis);
        MyBean sc2 = new MyBean("Test1", "Test2");
        in = new ObjectInputStream(fis);
        System.out.println(sc2);
    }
}

class MyBean implements Serializable {
    private final String a;
    private transient String b;
    public MyBean(String aa, String bb) {
        a = "Merit Campus: " + aa;
        b = "Program: " + bb;
    }
    public String toString() {
        return a + "\n" + b;
    }
}


Merit Campus: Test1
Program: Test2
Merit Campus: Test2
Program: Test1
Merit Campus: Test1
Program: null
Merit Campus: null
Program: Test2
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