I was going through a nice question and it was that...Suppose super class of a new class implement Serializable interface, how can you avoid new class to being serialized?
TH/he answer to this solution is ..as per my understandings...If Super Class of a Class already implements Serializable interface in Java then its already serializable in Java, since you can not unimplemented an interface its not really possible to make it Non Serializable class but yes there is a way to avoid serialization of new class. To avoid java serialization you need to implement writeObject () and readObject () method in your Class and need to throw NotSerializableException from those method.
Now could you guys please show me through a small program demo,,!!that will be a great help...!! thanks in advance..!!
NO. YOU write it. You clearly already have all the information you need available. And if you get stuck while trying to write it, google for examples. And, after you spend at least an hour trying to write it yourself and trying to figure out your problems by searching on your own, if you're still stuck, then post a question here, showing what you've tried, and providing details about what exactly you're having trouble with.
Why is it necessary to tell you this in almost every thread you post?
Saral Saxena wrote:Now could you guys please show me through a small program demo,,!!
Saral, if you are serious about learning to program in Java, you will need to take initiative yourself, instead of constantly asking other people to write examples for you.
The best way to learn programming is to experiment yourself. Write code yourself, if it doesn't work, carefully try to understand what the error messages mean, change your program and try again, until it works.
It's also much more fun when you do that - the satisfaction of solving a problem you have been working on for a while is nice.
Now, about this question. You know already exactly what has to be done, because you wrote this yourself:
Saral Saxena wrote:To avoid java serialization you need to implement writeObject () and readObject () method in your Class and need to throw NotSerializableException from those method.
It's very easy to make a short program with exactly this. The API documentation of the interface java.io.Serializable (<= link, click on it) tells you exactly what the writeObject() and readObject() methods should look like.
Try it yourself, and post your results, then we'll tell you if you did it correctly.