• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Extending a class that implements java.io.Serializable interface

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

- Can anyone please let me know in simple terms, the meaning of a Serializable class and what does it imply for that class (which implements java.io.Serializable)?

- And when extending a class that implements Serializable - is it necessary to also state on the class-definition of the extending class that it implements Serializable?

e.g
1. class Parent extends java.lang.Object implements Serializable

2. class Child extends Parent

is line 2 enough

or should it read:
3. class Child extends Parent implements Serializable.

Thanks
Siphiwe M
SCJP 1.5 (aspirant)
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Serializable is a marker interface.

It implies that the class can be serialized and it's state can be stored on to the disk in a file.

when we extend a class that implements serializable we need not specify it again. this behavior is as per standard behavior of java.

Correct me if i am wrong.
 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Serializable Class means
its objects can be serialized/persisted/saved.
As object is defined by its state which is turn is defined by its instance variables Value .
So Object and its State is saved on disk like any other file.
and later can be retireved.
eg
Before saving, Box class had an object b1( variables values ht=10 wt=70)
So with Serializable interface ,we can saved this object b1 ,with vales,later retrive same values.

2. No when super class implementing Serilizable,Chld class automatically implements Serializable.so need not explicit 'implements'
 
Ranch Hand
Posts: 1274
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy,

Welcome to the Ranch, Siphiwe!





this:

prints:
siphiwe instance of Serializable ?
yes


Some developers also would include the "implements Serializable" to the extending class, but only for clarity of the code.
But it's true, all extending classes implement all interfaces of the superclass automatically.

The javadoc tool also would include the fact that Siphiwe implements Serializable into the generated documentation.

Yours,
Bu.
 
Siphiwe Madi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for the clarity. Now I understand.

Regards,
Siphiwe M
 
Do not set lab on fire. Or this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic