• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Interfaces in Inheritance

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

class A is the parent class which implements Serializable interface. Class B is the child class which extends Class A.
Now my question is I don't want class B as Serializable, So can make class B as non Serializable class .. Is it possible?

I think one way is we can mark all variables as transient. Is there any other way?

Pls clarify me on this.

Thanks,
Senthil.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. Class B IS-A class A. If A is Serializable then B must be Serializable. Marking all variables transient would be a worthless kludge. Not only would it most likely break class A's contract but it wouldn't prevent class B from being serialized, specifically it wouldn't change that B is Serializable nor would it prevent A's data from being serialized. All it would serve to do is break the serialization, which is about the worst solution I can imagine. If class B should not be Serializable then either class A shouldn't be either or class B is not a class A and shouldn't extend it.
 
author
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by senthil rajan:
Hi Frnds,

class A is the parent class which implements Serializable interface. Class B is the child class which extends Class A.
Now my question is I don't want class B as Serializable, So can make class B as non Serializable class .. Is it possible?

I think one way is we can mark all variables as transient. Is there any other way?

Pls clarify me on this.

Thanks,
Senthil.



The best way to prevent serialization is to override the readObject() and writeObject() methods to throw a NotSerializableException. These two methods are used by the serialization process to serialize the object.

There should be a couple of examples on the internet that you can google for about this.

Henry
 
knowledge is the difference between drudgery and strategic action -- tiny ad
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic