interview questions…

So yesterday I had a phone interview with Rally. Overall, I think the interview went good, but one question he asked me was about polymorphism – “What is polymorphism?” to be exact.

We all learn about polymorphism in college along with things like multiple inheritance, weak/strong typing, and object oriented design. But I have always found questions involving these concepts have really funky answers that are sometimes hard to articulate. My first reaction was to say that polymorphism is having a class Foo that can act like class Bar. Well that’s not technically the right answer, but I am not sure its necessarily the wrong answer as well.

Polymorphism is defined in my CS3410 book (Data Structures and Problem Solving using Java – second edition by Mark Weiss) as the following –

A reference type can refence objects of several different types. When methods are applied to the polymorphic type, the operation that is appropriate to the actual referenced object is automatically selected. In Java, this is implemented as part of inheritance. Polymorphism allows us to implement classes that share common logic.

So if Student and Faculty both extend Person and you assign a newly created Student object to a Person reference and then call toString(), it will use the Student’s toString method and not the Person class method (that is unless the Student toString calls super.toString()). The appropriate implementation of the method is called at run-time through dynamic binding.

So that means that a Person class can indeed act like a Student class and vice-versa depending on the methods called.

Oh and another question he asked was what is the difference between a list and a set? This one always screws me up, I get them backwards 9 times out of 10. So here are the answers:

List – Can have duplicates and has a defined order.
Set – Cannot have duplicates and does not have a defined order.

Posted in: Uncategorized



This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

2 Comments

rssComments RSS transmitTrackBack Identifier URI


I'm excited for you!

Comment by David Duey on April 13, 2010 7:08 pm


J'ai insisté. Merci pour le partage.

Comment by comprimés hommes on May 20, 2010 3:37 pm

addLeave a comment

You must be logged in to post a comment.