wood burning stoves 2.0*
The moose likes Java in General and the fly likes Serializable interface. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Serializable interface." Watch "Serializable interface." New topic
Author

Serializable interface.

Sabitanjali sabitanjali
Greenhorn

Joined: Sep 30, 2003
Posts: 2
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

Joined: Mar 06, 2001
Posts: 1209
Object o = new Object();
System.out.println(o instanceof Serializable) --> prints false.
So i guess object is not serializable
Mahesh G Patil
Greenhorn

Joined: Oct 21, 2003
Posts: 10
Yes, you should get output as Serializable. But where is it mentioned that Object class implements Serializable interface ???
Mahesh
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

If the Object class were Serializable we would not have needed Serializable interface.


Groovy
Gustavo Adolpho Bonesso
Ranch Hand

Joined: May 11, 2002
Posts: 103
The Object class doesn�t implements Serializable interface or any other interface. This is the basis class of any other class in Java.


Gustavo Adolpho Bonesso<br />SCJP1.4
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
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...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serializable interface.
 
Similar Threads
Why java.util.Set is not Serializable?
Creation of objects and serialzation
advantage of blank interfaces??
Problem with Object Desirialization
Runtime API to find if the object is serialzable or not