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 Organizing Data Interfaces

overriding

what is overriding? and how to use it

overriding is writing a special functionality to your subclass, Example if Vehicle is Superclass, Cycle is Subclass, then method drive can be overidden in Cycle class.

1 Answer

Mohammad Laif
PLUS
Mohammad Laif
Courses Plus Student 22,297 Points

If you have parent class contains printDateMethod(), and you create a new class extended that parent class. So you end up with child class and parent class.

Now using printDateMethod() in the parent class output -> "12-31-2017".

But in the child class you want to change that output to -> "31-12-2017", therefore you can change printDateMethod() code inside your child class, but you need to write "@Override" above it, to notify the compiler (so he did not freak out, wondering why the child behave different than his parent).

that @Override called annotation, and there are more of them!

So overriding simply is replacing the parent code with new code in the child.