Site icon DataFlair

Quiz on Serialization and Deserialization in Java

quiz on serialization and deserialization in java

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Ever wondered how you can save the state of your Java objects and load them back later? Serialization and deserialization are powerful techniques that allow you to achieve just that.

This quiz will test your understanding of these crucial concepts in Java. By answering the multiple-choice questions, you’ll gain valuable insights into how to effectively serialize and deserialize objects in your Java programs. Ley’s test your knowledge.

Time limit: 0

Quiz Summary

0 of 15 Questions completed

Questions:

Information

You have already completed the quiz before. Hence you can not start it again.

Quiz is loading…

You must sign in or sign up to start the quiz.

You must first complete the following:

Results

Quiz complete. Results are being recorded.

Results

0 of 15 Questions answered correctly

Your time:

Time has elapsed

You have reached 0 of 0 point(s), (0)

Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)

Categories

  1. Not categorized 0%
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  1. Current
  2. Review / Skip
  3. Answered
  4. Correct
  5. Incorrect
  1. Question 1 of 15
    1. Question

    Which library file should be included in the program to perform serialization ?

    Correct
    Incorrect
  2. Question 2 of 15
    2. Question

    Which of the following is correct syntax for serialization in Java ?

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

    class A implements Serializable { 

    methods();

    }

    class B {

    methods();

    }

    class C extends A {

    method();

    }

    class Main {

    public static void main ( String argos [ ] )

    {

    C obj = new C();

    B obj1 = new B();

    }

    }

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    To perform serialization the class should do which of the following ?

    Correct
    Incorrect
  5. Question 5 of 15
    5. Question

     import java.io.serializable;

    class One implements Serializable {

    int number;

    public One()

    {

    this.number;

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    One o = new One(40);

    FileOutputStream file = new FileOutputStream(Document.txt);

    ObjectOutputStream out = new ObjectOutputStream(file);

    out.writeObject(number);

    }

    System.out.println(“The given  value is serialized”);

    }

    Correct
    Incorrect
  6. Question 6 of 15
    6. Question

    class Function {

    int a ;

    }

    class Sample extends Function {

    public void print() {

    System.out.println(a);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Function f = new Function(100);

    String filename = “File.txt”;

    FileOutputStream file = new FileOutputStream(filename);

    ObjectOutputStream out = new ObjectOutputStream(file);

    out.writeObject(f);

    }

    }

    Correct
    Incorrect
  7. Question 7 of 15
    7. Question

    Which of the following is defined as travelling a code into a network stream ?

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

     class Demo implements serializable {

    int a,b;

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Demo d = new Demo(99,101);

    String filename = “File.txt”;

    FileOutputStream file = new FileOutputStream(filename);

    ObjectOutputStream out = new ObjectOutputStream(file);

    out.writeObject(d);

    out.close();

    file.close();

    Demo Object;

    FileInputStream file1 = new FileInputStream(filename);

    ObjectInputStream input = new ObjectInputStream(file1);

    Object = input.readObject();

    System.out.println(Object.a + Object.b);

    }

    }

    Correct
    Incorrect
  9. Question 9 of 15
    9. Question

     class Serialization implements serializable {

    int a ;

    }

    class Main {

    public static void main ( String args [ ] )

    {

    String filename = “File.txt”;

    FileOutputStream file = new FileOutputStream(filename);

    ObjectOutputStream out = new ObjectOutputStream(file);

    out.writeObject(a);

    System.out.println(“Success”);

    }

    }

    Correct
    Incorrect
  10. Question 10 of 15
    10. Question

    Which of the following is an advantage of serialization ?

    Correct
    Incorrect
  11. Question 11 of 15
    11. Question

    class SerializationSample implements Serializable {

    int count = 0;

    public SerializationSample(int a) {

    for(a=5)

    {

    ++count;

    System.out.println(count);

    }

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    SerializationSample s = new SerializationSample(5);

    FileOutputStream file = new FileOutputStream(filename);

    ObjectOutputStream out = new ObjectOutputStream(file);

    out.writeObject(s);

    file.close();

    }

    }

    Correct
    Incorrect
  12. Question 12 of 15
    12. Question

    class Sample implements Serializable {

    static int a;

    public Sample(int x) 

    {

    a=x;

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Sample object = new Sample(10);

    String filename = “file.txt”;

    FileOutputStream file = new FileOutputStream(filename);

    ObjectOutputStream out = new ObjectOutputStream(file);

    out.writeObject(object);

    file.close();

    System.out.println(a);

    }

    }

    Correct
    Incorrect
  13. Question 13 of 15
    13. Question

    Which stream is used to call the method writeObject() in Serialization ?

    Correct
    Incorrect
  14. Question 14 of 15
    14. Question

    Which of the following is correct syntax for Deserialization in Java ?

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

    class Demo implements serializable {

    String name;

    int branches;

    public Demo(String a , int b )

    {

    name=a;

    branches=b;

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Demo d = new Demo(“DataFlair”,25);

    String filename = “File.txt”;

    FileOutputStream file = new FileOutputStream(filename);

    ObjectOutputStream out = new ObjectOutputStream(file);

    out.writeObject(d);

    Fileoutputstream file = new FileOutputStream(filename);

    ObjectInputStream input = new ObjectInputStream(file);

    input.writeObject(d);

    System.out.println(input.name);

    }

    }

    Correct
    Incorrect

Summary:

Ready to put your Java serialization and deserialization knowledge to the test? This short quiz covers essential aspects of these techniques, helping you assess your grasp of the subject.

Whether you’re a beginner or a seasoned Java developer, this quiz is a valuable tool for identifying areas for improvement and solidifying your understanding.

So, take the quiz, challenge yourself, and gain valuable insights into effectively persisting and restoring the state of your Java objects.

Exit mobile version