Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Class declaration??  RSS feed

Sagar Sharma
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i ran up into a question at a mock exam,
Q) Given an Answer class which behaves like a File and has a Vector, a boolean and a color. What is the correct declaration??

I wrote:
public class Answer extends File{
Vector v;
Color c;
boolean b;
I was amazed to see the following answer:
public class Answer extends File implements Serializable

Pls clarify

greg clarke
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An odd one. First, I don't think serialization is in the Programmer's certification objectives - I've just done a quick search on the objectives at Marcus Green's site and didn't get a hit.
Second, the question looks like a "is a" versus a "has a" object theory question and I would have answered as you did, except that, judging by the supplied answer, they only wanted the class declaration. If that was made clear in the question then it might have been a cryptic clue to the answer they wanted.
Thirdly, the File class implements Serializable, so by extending File your Answer class also implements Serializable. This means your answer also contains the correct answer.
But, all that aside, and working backwards from the answer they've given, I guess their rationale is that "behaving like a file" means achieving some sort of persistence and the Serializable interface enables a type of persistence, I suppose.
Hopefully the real test won't have such a loose question, and hopefully we don't need to cover Serializable.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!