This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Regarding Serialiazble interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regarding Serialiazble interface" Watch "Regarding Serialiazble interface" New topic
Author

Regarding Serialiazble interface

Prakash Pillai
Greenhorn

Joined: Feb 17, 2002
Posts: 12
Hi guys,
I am curious to know .
1.How Serializable interface works.As dosn't have any method to implement ?
2. Serializable s=new String("Hello");
How the above statement works or gets complied,as String is class and Serializable is interface ?
Thanx,
Prakash
Graeme Brown
Ranch Hand

Joined: Oct 13, 2000
Posts: 193
1. Serializable is a marker to the virtual machine to show that instances of implementing classes may be serialized. There is no new behaviour that you need to implement to achieve this, under normal cirumstances, so no need for Serializable to define any new methods.
2. This is to do with inheritance and polymorphism. The full definition of class String is:

this means that String is of class String but also has type of Object, Serializable and Comparable.
Therefore you can provide an instance of a String any where that you need either a String, an Object, a Serializable, or a Comparable.
An informal way of checking this is by the "is a" test. If you can say String is a Serializable then it is OK.
For more info read How my Dog learned Polymorphism
Jorge Phillips
Ranch Hand

Joined: Jun 03, 2001
Posts: 43
As Graeme well puts it, a String implements the Serializable interface. When you do
Serializable s = new String("bar");
you can invoke any methods on s that are declared in the Serializable interface, but String methods would be hidden. Likewise say if s is of type Object.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding Serialiazble interface