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 trialshu Chan
2,951 PointsCan someone expalin to me what is @Override?
My understanding of this is that it tells the program it must run the code that is within it's scope as well as the default code it would run. Am I correct?
2 Answers
Mohammad Laif
Courses Plus Student 22,297 PointsIf 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!
Tal Idan
1,742 PointsAdding to what Mohammad said, I personally dont use the @Override line and everything works just fine. I believe it is used to make us "Better Programmers", thus allowing future programmers and developers who will take a look at our code will be able to understand that the method we've written is an override.