• Post Reply Bookmark Topic Watch Topic
  • New Topic

Which two are benefits of polymorphism?  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got a question which I think the answer is wrong.

The question is:

Which two are benefits of polymorphism?

A. Faster code at runtime

B. More efficient code at runtime

C. More dynamic code at runtime

D. More flexible and reusable code

E. Code that is protected from extension by other classes

They say that the correct answers are: B and D. However, I think that the correct answers are: C and D.

What do you think?
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marco Pierre Fernandez Burgos wrote:They say that the correct answers are: B and D. However, I think that the correct answers are: C and D.
What do you think?

I think any one of B, C or D could be correct, depending on what they mean by "dynamic". So, on that basis, I'd say that B and D is "more correct" than C and D.

The reason why B is correct may be answered by asking yourself the following question: If you didn't have polymorphism, what would your code look like?

This is a question that C programmers have wrestled with for many years.

Winston
 
Sheriff
Posts: 4295
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and welcome to the Ranch!
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote: If you didn't have polymorphism, what would your code look like?

This is a question that C programmers have wrestled with for many years.

Winston


It would be objects or structures with pointers to functions. Thats how we did polymorphism.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shawn Lau wrote:It would be objects or structures with pointers to functions. Thats how we did polymorphism.

OK, but it takes a lot of building. And unless you know the type beforehand, you end up with a lot of dispatch code (anyone remember COM?).

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!