top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Java: When B is serialized then also the fields of class A will be serialized?

+2 votes
392 views

If class A does not implement Serializable but a subclass B implements Serializable.

posted Sep 30, 2013 by Manish Negi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

Only the fields of Serializable objects are written out and restored. The object may be restored only if class A has a no-arg constructor that will initialize the fields of non-serializable supertypes. If the subclass has access to the state of the superclass it can implement writeObject and readObject to save and restore that state.

answer Sep 30, 2013 by Satyabrata Mahapatra
Similar Questions
+2 votes

Given 2 strings, a and b, return a string of the form shorterString+longerString+shorterString, with the shorter string on the outside and the longer string on the inside. The strings will not be the same length, but they may be empty (length 0). If input is "hi" and "hello", then output will be "hihellohi".

+1 vote

Java is a purely Object Oriented programming language or not.......?
If Not
Then write a program without class & objects.......

+3 votes

In Java
I am using statement a += b where a is int and b is double, when I use a += b, it won't give error but in case of a = a + b it gives error, why ?

...