• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this OCAJ question ambiguous, or am I missing something?

 
Andy Ball
Greenhorn
Posts: 20
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies if this is the incorrect forum for such questions, if so, please can a Mod move accordingly..?

Anyway, - I'm just doing some Enthuware mocks (Which are fantastic by the way) and I came across this question.
Now when I read it, I read 'Mechanisms are different' to mean may have different method actions, may have different arguments, hence my answer.
Is there some clue in the text which suggests that overriding only is the answer, or is it a 50/ 50 guess job & hope you pick right?

Here's the Q.

You are modeling a class hierarchy for living things. You have a class LivingThing which has an abstract method reproduce(). Now, you want to have 2 subclasses of LivingThing - Plant and Animal. Both do reproduce but the mechanisms are different. What would you do?

1) Overload the reproduce method in Plant and Animal classes
2) Overload the reproduce method in LivingThing class.
3) Override the reproduce method in Plant and Animal classes
4) Either overload or override reproduce in Plant and Animal classes, it depends on the preference of the designer.


I was torn between 3 & 4, but I guessed 4 as It doesn't say how the mechanisms vary ( i.e one could have reproduce(String fuel, int pollenCount) and another could have reproduce(Animal mate)

The correct answer was 3, suggesting that the reproduce methods will always have the same argument set, - how is that clear from the question?


Man,.. I'm losing it. Roll on Tuesday!
 
Andy Ball
Greenhorn
Posts: 20
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
has an abstract method reproduce()

...oops!
I see now.

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy,
Have a cow for answering your own question! It's great because the next person who has the same question gets to see the answer.

Also, I moved this post to our OCJA forum for you. This where your next question on the exam will go.
 
Mikalai Zaikin
Ranch Hand
Posts: 3371
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Ball wrote:has an abstract method reproduce()

...oops!
I see now.



Well, actually from question is not clear if Plant and Animal are abstract or concrete.

In case they may be abstract, they can just overload "reproduce" method.

So, your initial answer (4) can be considered as correct too 8-)

regards,
MZ
 
Andy Ball
Greenhorn
Posts: 20
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mikalai Zaikin wrote:
Andy Ball wrote:has an abstract method reproduce()

...oops!
I see now.



Well, actually from question is not clear if Plant and Animal are abstract or concrete.

In case they may be abstract, they can just overload "reproduce" method.

So, your initial answer (4) can be considered as correct too 8-)

regards,
MZ


'tis what I thought good sir,

But alas, the Enthuware software telleth me different.

the scoundrel.
 
Mikalai Zaikin
Ranch Hand
Posts: 3371
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Ball wrote:
Mikalai Zaikin wrote:
Andy Ball wrote:has an abstract method reproduce()

...oops!
I see now.



Well, actually from question is not clear if Plant and Animal are abstract or concrete.

In case they may be abstract, they can just overload "reproduce" method.

So, your initial answer (4) can be considered as correct too 8-)

regards,
MZ


'tis what I thought good sir,

But alas, the Enthuware software telleth me different.

the scoundrel.


The good thing that most likely on real exam you won't get ambiguous questions, as they have gone through multiple internal reviews and beta stage.
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3817
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mikalai Zaikin wrote:
Andy Ball wrote:has an abstract method reproduce()

...oops!
I see now.



Well, actually from question is not clear if Plant and Animal are abstract or concrete.

In case they may be abstract, they can just overload "reproduce" method.

So, your initial answer (4) can be considered as correct too 8-)

regards,
MZ

Actually, the question contains enough information to strike out overloading. The whole purpose of having an abstract method in the base class is to make use of polymorphism. The wordings of the question - same method different implementation by sibling classes - is actually a textbook use case of introducing polymorphism.
If Plant and Animal were abstract, one could certainly overload reproduce methods and make them compile. But this is not a compilation question. It is a design question. I think overloading is an unambiguously a wrong option.

Even so, the question has been updated to make it clear that Plant and Animal are not abstract.

thank you,
Paul.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic