Win a copy of Head First Android this week in the Android 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

polymorphism

 
Trailboss
Posts: 23400
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you think?
Is polymorphism demonstrated by method overriding or method overloading?
I'm taking a mock SCJP2 test and I don't agree with the answer given.
 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Method overriding, definately.
overriding:
<pre>
class Base {
void x(String s) { System.out.println(s) }
}
class A extends Base {
void x(String s) { super.method("A" + s) }
}
class B extends Base {
void x(String s) { super.method("B" + s) }
}
</pre>
Which exhibits polymorphism (a container of 'Base's may actually contain 'A's and/or 'B's)
overloading:
<pre>
class Base {
void x(String s) { System.out.println(s) }
void x(int i) { System.out.println(i) }
}
</pre>
which doesn't show any polymorphism (a container of 'Base's will only contain 'Base's)
Am I misunderstanding it? Did the answer say something else?
 
paul wheaton
Trailboss
Posts: 23400
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with you. I also agree with the "definitly" part.
I think the question was something like: "which of these features of Java represent polymorphism?" And then there is a list. Check all that apply. Method overriding was on the list. So was method overloading. My only pick was overriding. I got it wrong. The "answer" was only one pick: "overriding". I found several errors in the test that I could prove - this one is more of a "proof by vote" thing. We have to agree on what we mean by polymorphism.
On to the next mock exam ....

 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic