This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a flower (🌹) or copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java (📚) this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
master stewards:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
garden masters:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
gardeners:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Serializable question

 
pioneer
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


10. class Car implements Serializable {
11. Wheels w;
12. }
13.
14. class Wheels { }

If you attempt to serialize an instance of Car, what is the result?

A. Compilation fails.
B. One object is serialized.
C. Two objects are serialized.
D. An exception is thrown at runtime.



What will be the correct answer?


Source: Sun practice exam


[EDIT] YEAH Swarna, I say that too, but the source says 'B'.
Surprised!!!

Thanks,
cmbhatt
[ April 27, 2007: Message edited by: Chandra Bhatt ]
 
pioneer
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how abt D?
 
pioneer
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya they say that
I understand it as follows:

Wheels is a object which cannot be serialized. Cars can be serialized. Wheels is not instantiated yet inside Cars so Cars object does not have Wheels object. Thus Cars object can be serialized and one object gets serialized. If Wheels object would have been instantiated then the Cars object would have a wheels object inside it and in that case that object cannot be serialized. It would throw NotSerializable exception then.

Its not easy to be a compiler
[ April 27, 2007: Message edited by: megha joshi ]
 
swarna dasa
pioneer
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should have guessed it, if it was as simple as D, you wouldn't have posted it in the first place
 
Chandra Bhatt
pioneer
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, You took the question in right way!

Until, Wheels is instantiated, no problem to serialize the Cars object,
which HAS-A Wheels.



Its not easy to be a compiler.



But I am sure It not easy to think like a programmer, for the compiler.



Thanks,
cmbhatt
 
pioneer
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just one small point. I take it that this question is not one of those from Sun's Practive Exam that you have agreed to not to disclose? That is, it is not from Sun's online US$ 75 test?
[ April 28, 2007: Message edited by: Barry Gaunt ]
 
pioneer
Posts: 111
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

10. class Car implements Serializable {
11. Wheels w;
12. }
13.
14. class Wheels { }



just check the answer when we create new Wheels

Wheels w= new Wheels();


Thanks,

Abdul Mohsin
 
pioneer
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by swarna dasa:
how abt D?



I too go with D.
 
Chandra Bhatt
pioneer
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,


class Car implements Serializable {
Wheels w;
}

class Wheels { }



I do agree with you all, but only when a new instance of the Wheels is created. In this question option "B" is correct. Having only a reference of
the class that is not Serializable is no more sin that could hinder the proper Serialization of the containing class object.

Megha described the rest part very well.

Barry, the question I picked from says "Courtesy to sun practice exam"!
What to do, should I remove this question?
[ April 30, 2007: Message edited by: Chandra Bhatt ]
 
Oh, sure, you could do that. Or you could eat some pie. While reading this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!