What is the purpose of a Transient variable?

Solution:

A transient variable would not be serialized even if the class to which it belongs is serialized.

Sample class which has transient variable is shown below:

Transitent variable

public class Paper implements Serializable
{
    private int id;
    private String title;
    private String author;
    private transient int version = 1;
   
}
0 answers