Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8123005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:01:20+00:00 2026-06-06T06:01:20+00:00

class Parent implements Serializable{ …….. } class Child extends Parent{ private void writeObject(ObjectOutputStream oos)

  • 0
 class Parent implements Serializable{

      ........
 }

 class Child extends Parent{

      private void writeObject(ObjectOutputStream oos) throws IOException {
            throw new NotSerializableException();
      }
      private void readObject(ObjectOutputStream oos) throws IOException {
            throw new NotSerializableException();
      }

 }

The above code shows how child avoids Serializable if the parent is already implemented Serializable. It seems to be a bad design and confusing at some points, so I am wondering in what circumstance would you consider to do that ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:01:23+00:00Added an answer on June 6, 2026 at 6:01 am

    If the parent is tagged as Serializable then every child should be serializable by design. Otherwise the bad design choice is not how you forbid serialization by throwing exceptions but the fact that Parent shouldn’t have been Serializable.

    Since there is no way to remove an interface implemented in a an ancestor class you have no choices: raising an exception is always better then serialize something which is not meant to be serialized, this would let you think everything went fine until something will go wrong with the serialized data. There is always a reason to forbid serialization: just adding a field in the child class which is not serializable is enough (unless you can use it as transient but this is not always possible, if the field contains critical information).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Class Child extends Parent. Parent implements protocol C which has optional methods, including -(void)d
Here is my custom CursorAdapter: public class TasksAdapter extends CursorAdapter implements Filterable { private
I have a parent and child class that both need to implement IDisposable .
Class parent { protected void myMethod() { if(someCodition) { //return this as well as
Example models: class Parent(models.Model): name = models.CharField() def __unicode__(self): return self.name class Child(models.Model): parent
I have a parent class Parent and a child class Child , defined thus:
Here is my code @Entity class Parent extends Person { @OneToMany(cascade = CascadeType.ALL, fetch
I have a Parent/Child object/mapping as follows: class Parent { int Id; string name;
Suppose we have 2 classes, Child, and the class from which it inherits, Parent.
This code show the error to add unimplemented methods. public class Child implements IResponse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.