File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Inheritence and Interfaces question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritence and Interfaces question" Watch "Inheritence and Interfaces question" New topic
Author

Inheritence and Interfaces question

Alok Pota
Ranch Hand

Joined: Mar 07, 2001
Posts: 185
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

Joined: Mar 06, 2001
Posts: 123
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

Joined: Jun 12, 2001
Posts: 76
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)


Sun Certified Java Programmer
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inheritence and Interfaces question