0

In 2 java classes , If class A implements Serializable and class B extends A, then by default is Class B Serializable also? From what I understand, it is.

0

2 Answers 2

2

Yes, this is correct. However, note that all fields of A and B must also contain Serializable objects, otherwise there will be a NotSerializableException at runtime when you try to serialize them.

Sign up to request clarification or add additional context in comments.

Comments

1

Yes. This follows from the concept of inheritance in Java. Since A is serializable and B extends A, B is serializalbe. Worth noting, notice that B is not "Default" Serializable, there is no choice as long as B extends A.

3 Comments

I don't know what your last sentence means.
This means that if you extend class B, A will always be considered Serializable.
You already said that in your scond sentence. The last sentence just confuses things. I would delete it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.