• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help me with this question from mock exam

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your 17 year old son wanted a car for his birthday, and he was over the moon with the rusty old Al Bundy Dodge you bought him.

On the other hand, your 21 year old daughter wanted a Mercedes for her birthday, and was not amused when she unwrapped the keys to a different, but similar, Al Bundy Dodge.

This scenario describes:

A. the relation between parent and ancestor classes
B. data encapsulation
C. object instantiation
D. the unidirectional nature of polymorphism

The correct answer was D, but I don't understand the answer (or the question for that matter). Would someone please explain to me what this question is all about and why it the answer is D?

BTW this is not a real exam question, this is from http://www.scja.com/ (Fundamentals of JDK).

Thanks
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing like a challenging question that combines both Java, and American pop culture.

The son wants a car. A Dodge is-a car. By the way, an Al Bundy Dodge refers to the broken down Dodge car that Al Bundy always complained about in the TV show 'Married with Children.'

Married with Children TV Show

The point is, the son wants a car, and a Dodge is-a car. If you want something generic, like a car, and you get one, a specific type of car, then life is good. This is polymorphism in action. When you want a certain type of object, any subtype of that object will suffice.

On the other hand, the daughter wants a very specific type of car - a mercedes. A beaten up old dodge is not a mercedes. A brand new BMW isn't a Mercedes either. The daughter was very specific - she didn't want just a car, but instead, a very specific type of car. Since she didn't get the type that she wanted, she was not happy.

The same thing applies in Java. When you want an Object, any old Object will do. If you want a java.lang.Object, and I give you a java.awt.Color, life is good; if I give you a String, life is good; if I give you a Byte, life is good. On the other hand, if you want a String, and I give you a Byte, Object or java.awt.Color, there will be problems.

With polymorphism, you can ask for a general object, and be given any subclass; but if you are given something more general that the type you are asking for, there will be problems. This is how polymorphism is unidirectional.

Shoot me an email if you have any more questions: male att cameronmckenzie dawt com

-Cameron McKenzie
[ February 25, 2007: Message edited by: Cameron W. McKenzie ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...This scenario describes:

A. the relation between parent and ancestor classes
B. data encapsulation
C. object instantiation
D. the unidirectional nature of polymorphism
E. a question writer who loses focus by trying to be clever :roll:
 
Sid Bachtiar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cameron,

Thanks for the excellent explanation. Soon after I posted the question above, I realised the website where the mock exam is also provides explanation of the answer, but I still didn't understand after reading it.

To marc,

Yeah, when I read the question, I was like 'What the...'.
 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you just have to click and drag where it says 'don't click and drag' and you can see the answer.

A bit of a nutty question, I admit. That's the 11th question in a free, 11 question exam, where most of the questions are very dry and to the point. I believe strongly that part of the elegance of Java is how it models in code, many of the ideas we see around us everyday. Inheritance and polymorphism aren't just concepts releated to Java, they're concepts related to life.

It's all about broadening the mind.

Cheers!

-Cameron
[ February 28, 2007: Message edited by: Cameron W. McKenzie ]
 
Sid Bachtiar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cameron,

Are you the author of scja.com?

I think there's an incorrect result in one of the questions:

Which of the following must have their code compiled before being able to deliver content to the client?
A. Java Applets
B. Java based Swing applications
C. Java Server Pages
D. JavaScript

I answered ABC but the result checker said the correct answer is ABD.

It's question 12 of 'Fundamental Java Based Client' set of questions.

Kind Regards,

Sid
 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those free exams. What do you expect?



I'll fix that up right away. Thanks.

-Cameron
 
Sid Bachtiar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Cameron W. McKenzie:
Those free exams. What do you expect?



I'll fix that up right away. Thanks.

-Cameron



Hi Cameron,

I appreciate the availability of the free exams, they are useful and I enjoyed trying them. I was just letting you know so you could fix it.

Btw, aren't they sort of like the advertisement/preview of the paid ones? So if they're broken ...

Kind Regards,

Sid Bachtiar
 
reply
    Bookmark Topic Watch Topic
  • New Topic