0

I have gone through java docs for Class there I have seen class implements Serializable click here, In the image as the class by default implements serializable why do we need to write extra line implements serializable for classes when we are dealing with situations like

import java.io.Serializable;  
public class Student implements Serializable{  
 int id;  
 String name;  
 public Student(int id, String name) {  
  this.id = id;  
  this.name = name;  
 }  
} 

when we want to travel object's state on the network.

  • I got a strike for my first question but *boris the spider* you should consider if that link answers my question in my case it has nothing to do with my question please go through question again not the title because they all sound the same thanks and regards. – psycoder Oct 08 '16 at 15:46
  • what doesn't the link cover? What is your doubt? – Peter Lawrey Oct 08 '16 at 15:59
  • Only data value objects should be serializable and you need a means of preventing an object which was never intended to be serialized from doing so. This is all to easy to do by mistake other wise. – Peter Lawrey Oct 08 '16 at 16:02
  • @PeterLawrey: As I understand it, the question is not about the purpose of serialization. He simply mixed up `Class` and `Object`, see my answer. – Frank Puffer Oct 08 '16 at 16:06
  • @FrankPuffer possibly. Though if all classes were serializable what would be the point of the interface at all. +1 for answer. – Peter Lawrey Oct 08 '16 at 16:10

1 Answers1

1

Each class is derived from Object by default, not from Class. Only Class implements Serializable. I do agree that the naming of these standard classes can be a bit confusing.

Frank Puffer
  • 8,135
  • 2
  • 20
  • 45