GeeCON Prague 2014*
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


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: 19697
    
  20

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: 42050
    
  64
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 - my free Android networking tools app
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: 42050
    
  64
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.
 
GeeCON Prague 2014
 
subject: extending a class which implements Serializable