Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Serializable interface.

 
Greenhorn
Posts: 2
  • 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.
 
Ranch Hand
Posts: 1209
  • 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
 
Greenhorn
Posts: 10
  • 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
 
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the Object class were Serializable we would not have needed Serializable interface.
 
Ranch Hand
Posts: 103
  • 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.
 
Ranch Hand
Posts: 3178
  • 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...
 
Let's get him boys! We'll make him read this tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic