Ness Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

In ur B class, implement the readObject(OutputStream out) and writeObject(InputStream in) methods.
If a class contains these methods, then during Serialization the JVM calls them to do the serialization process.
In this methods, simply throw a NotSerializable Exception.

- Anand January 30, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

But JVM will look into readObject(OutputStream out) and writeObject(InputStream in) methods only if class is implementing Externizible right? Here it is Serializable interface?

- Shiv February 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

http:java.sun.com developer technicalArticles Programming serialization
Stop That Serialization!
OK, we have seen quite a bit about the serialization process, now let's see some more. What if you create a class whose superclass is serializable but you do not want that new class to be serializable? You cannot unimplement an interface, so if your superclass does implement Serializable, your new class implements it, too (assuming both rules listed above are met). To stop the automatic serialization, you can once again use the private methods to just throw the NotSerializableException. Here is how that would be done:

10 private void writeObject(ObjectOutputStream out) throws IOException
20 {
30 throw new NotSerializableException("Not today!");
40 }
50 private void readObject(ObjectInputStream in) throws IOException
60 {
70 throw new NotSerializableException("Not today!");
80 }

Any attempt to write or read that object will now always result in the exception being thrown. Remember, since those methods are declared private, nobody could modify your code without the source code available to them -- no overriding of those methods would be allowed by Java.

- Anonymous June 08, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

add writeReplace() and readResolve() methods to B

- ps May 02, 2011 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More