Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritence and Interfaces question

 
Alok Pota
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class SuperObject implements Serializable {
}
class SubObject extends SuperObject {
}
Do I have to make SubObject implement Serializable or does it automatically become Serializable?

 
pjoisha
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would inherit that from its super class ...
public class Sample {
public static void main(String[] args) {
C1 c1 = new C1();
System.out.println((c1 instanceof java.io.Serializable));
C2 c2 = new C2();
System.out.println((c2 instanceof java.io.Serializable));
}
}
class C1 implements java.io.Serializable {}
class C2 extends C1 {}
Thx,
PJ
 
Frank Zheng
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a little addtion to your question.
You can use the key word "transient "to say some variables are not to be serialized and this is used to protect sensitive data from being written to a stream.
Frank
(scjp)
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alok,
Prashanth is correct. In order to support the answer I can point to the AWT classes. If you have noticed that all AWT classes are subclasses of Component.
Component implements Serializable
Button doesn't implicitly implement any interface
Yet from experience and/or books we know that all AWT components are serializable! Therefore you have real proof that subclasses inherit all the functionality of the superclass.
Regards,
Manfred.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic