This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serializable interface.

 
Sabitanjali sabitanjali
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class A which is serializable and class B extends class A. Then class B is serializable. Isn't it?
Class A implements seriazible {
}
Class B extends A{
public static void main(String args[]) {
B b = new B();
if (b instance of Serializable) {
System.out.println("Serialiazable");
} else {
System.out.println("Not serializable");
}
}
}

The output is serializable. But why the same does not appy with object class? The object class is serializable, and all other classes extend the object class. But if you don't implement the serializable interface, the class does not become serializable.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object o = new Object();
System.out.println(o instanceof Serializable) --> prints false.
So i guess object is not serializable
 
Mahesh G Patil
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you should get output as Serializable. But where is it mentioned that Object class implements Serializable interface ???
Mahesh
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the Object class were Serializable we would not have needed Serializable interface.
 
Gustavo Adolpho Bonesso
Ranch Hand
Posts: 103
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Object class doesn�t implements Serializable interface or any other interface. This is the basis class of any other class in Java.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
If the Object class were Serializable we would not have needed Serializable interface.

Nice tip, Pradeep!!! Why do we need that Serializable interface, if the based "Object" class is serialized... Coz almost everthing in Java are objects...
It is just for the other objects that we need to make them serializable in the situation that we really need to do...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic