• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

extending a class which implements Serializable

 
abinash das
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A implements Serializable
{
}
class B extends A
{
}
I that mean class B is serialized ?
 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
abinash das
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If So, then Why
In case Of servlets
both GenericServlet and Httpservlet both are implementing Serializable
interface,though Httpservlet extends GenericServlet .
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I understood.
Thank you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic