Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures Getting There Object Inheritance

Andrew Trachtman
Andrew Trachtman
3,680 Points

What are the key differences between polymorphism, overloading and overriding

As far as I can tell, the main differences are that: -Overriding replaces superclass functionality entirely using an identical method name and parameters and should be annotated.

-Overloading is when you take an existing method and essentially define it again, but using different parameters which Java sees an a completely different method.

-Polymorphism is when you extend the base functionality of a superclass. You give some base functionality to the child classes and then the child classes can develop their own behaviors.

So, if you override or overload a parent's methods, is that technically classified as just overriding or overloading? Or would it be polymorphism?

2 Answers

Brandon Khan
Brandon Khan
21,619 Points

still learning but this is what ive gathered @Override allows you to put your own code in the method you are overriding so if you want the toString() to always add something to the item you are making a string you would override it. (maybe a bad example) when you get into Android Studio you will use override a bit more and it'll make sense.

as for polly when when you declare a class so public class Example{} your going to add extends SomeClass to it the class so you can use all the methods and variables in that calss it should look like

public class Example extends SomeClass{ //your code here


now the Example class has all the properties of SomeClass on top of whatever code you add w/o effecting SomeClass....

my 2cents maybe it'll help.

Think of it like this. The child inherits some habits from the parent. The child can either do things like it was taught aka inherit, or change those habits for its own uses.

Overriding just means using the same function signature to change the inherited methods from a parent.

Polymorphism is just a concept in CS that objects can have a mix of some inherited behaviors aka methods and some unique to their own class.

Hope this helps!