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 trialJoel Lithgow
7,414 PointsBike Class example question
As Craig gave the example in the video of the Bike (super) Class which has its methods and then the Road Bike (child) Class and the Mountain Bike (child) Class which inherit methods from their parent Bike Class, however if you were to change one of these methods in the child class would you need to type @override for every single method? If so this seems very "DRY".
basically im not understand when you use override and if you use it a lot doesn't it come to be more of a hassle then helpful?
2 Answers
Mario Blokland
19,750 PointsHi Joel Lithgow,
you don't have to use the @Override annotation. But it has its benefit if you do so. The number one reason most people use this annotation is, that the compiler will tell you whether you really have overwritten the parent method.
When does this help? Say thay you want to override a method named renameMe()
but you accidentally typed it renaneMe()
. Then the compiler will tell you, that you didn't override any method (because of the spelling error), so you can correct your mistake without searching too long.
Checkout this link: Override annotation.
Or this for more explanation: Java predefined annotations
Rachelle Wood
15,362 PointsIt also has to do with telling the compiler that you are overriding the default method of the Object superclass in your customized subclass. If Oracle ever decides to deprecate something in the Object superclass that just so happens to be part of your subclass, the compiler will alert you if you annotated the method in question with "@Override".