File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Serializable interface." Watch "Serializable interface." New topic

Serializable interface.

Sabitanjali sabitanjali

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) {
} 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

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

Joined: Feb 27, 2002
Posts: 8927

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

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
I agree. Here's the link:
subject: Serializable interface.
It's not a secret anymore!