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.
Which library file should be included in the program to perform serialization ?
Correct
Incorrect
Question 2 of 15
2. Question
Which of the following is correct syntax for serialization in Java ?
Correct
Incorrect
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
Question 4 of 15
4. Question
To perform serialization the class should do which of the following ?
Correct
Incorrect
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
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
Question 7 of 15
7. Question
Which of the following is defined as travelling a code into a network stream ?
Correct
Incorrect
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
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
Question 10 of 15
10. Question
Which of the following is an advantage of serialization ?
Correct
Incorrect
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
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
Question 13 of 15
13. Question
Which stream is used to call the method writeObject() in Serialization ?
Correct
Incorrect
Question 14 of 15
14. Question
Which of the following is correct syntax for Deserialization in Java ?
Correct
Incorrect
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.
Did we exceed your expectations? If Yes, share your valuable feedback on Google
DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.