This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets 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: 19649
    
  18

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: 41052
    
  43
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: 41052
    
  43
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.
 
Don't get me started about those stupid light bulbs.
 
subject: extending a class which implements Serializable
 
Similar Threads
how makeChild classes as Non Serializable if parent class is Serializable in java ?
Serialization
Serializable interface.
regarding the marker interface
serialization question