This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes extending a class which implements Serializable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "extending a class which implements Serializable " Watch "extending a class which implements Serializable " New topic
Author

extending a class which implements Serializable

abinash das
Ranch Hand

Joined: Apr 26, 2008
Posts: 52
class A implements Serializable
{
}
class B extends A
{
}
I that mean class B is serialized ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19557
    
  16

Originally posted by abinash das:
class A implements Serializable
{
}
class B extends A
{
}
I that mean class B is serialized ?

Yes it is.

Through inheritance, B also implements Serializable.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
That doesn't mean that B is serializable, though. You need to ensure that it does not contain non-transient fields that are not serializable.


Ping & DNS - updated with new look and Ping home screen widget
abinash das
Ranch Hand

Joined: Apr 26, 2008
Posts: 52
If So, then Why
In case Of servlets
both GenericServlet and Httpservlet both are implementing Serializable
interface,though Httpservlet extends GenericServlet .
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
There's no harm in class B declaring that it implements Serializable as well. It helps anyone looking at the source code or the javadocs, because they can see the implemented interfaces right away (without having to look at the superclass).
abinash das
Ranch Hand

Joined: Apr 26, 2008
Posts: 52
Now I understood.
Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: extending a class which implements Serializable
 
Similar Threads
Serializable interface.
Serialization
regarding the marker interface
serialization question
how makeChild classes as Non Serializable if parent class is Serializable in java ?