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.
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
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
- Not categorized 0%
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- Current
- Review / Skip
- Answered
- Correct
- Incorrect
-
Question 1 of 15
1. Question
Which library file should be included in the program to perform serialization ?
CorrectIncorrect -
Question 2 of 15
2. Question
Which of the following is correct syntax for serialization in Java ?
CorrectIncorrect -
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();
}
}
CorrectIncorrect -
Question 4 of 15
4. Question
To perform serialization the class should do which of the following ?
CorrectIncorrect -
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”);
}
CorrectIncorrect -
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);
}
}
CorrectIncorrect -
Question 7 of 15
7. Question
Which of the following is defined as travelling a code into a network stream ?
CorrectIncorrect -
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);
}
}
CorrectIncorrect -
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”);
}
}
CorrectIncorrect -
Question 10 of 15
10. Question
Which of the following is an advantage of serialization ?
CorrectIncorrect -
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();
}
}
CorrectIncorrect -
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);
}
}
CorrectIncorrect -
Question 13 of 15
13. Question
Which stream is used to call the method writeObject() in Serialization ?
CorrectIncorrect -
Question 14 of 15
14. Question
Which of the following is correct syntax for Deserialization in Java ?
CorrectIncorrect -
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);
}
}
CorrectIncorrect
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.
