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!

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



what is "@override" in the java file of the app?

2 Answers

Jean Simmons
Jean Simmons
7,615 Points

I've actually had this question before. @Override is an annotation that [isn't necessarily needed as long as you continue to accurately key the correct API for the supertype method you wish to override. The potential hazard is that your app will successfully compile, execute and call the supertype method on a superclass or interface which, although it may not cause your application to crash, would provide you with results that you would not expect.] A college professor told me this once after I tried compiling a project several times in Netbeans and couldn't get it to work because Netbeans kept expecting the use of @Override and started adding annotations to my code that I didn't quite understand.

If you check StackOverflow you can find some good answers to give you a better idea: http://stackoverflow.com/questions/4341432/what-does-override-mean

You have lots of ready made classes available to you, and these classes have ready made methods. For example, I'm looking at my project and I see that my MainActivity extends AppCompatActivity. If I go into AppCompatActivity I see it contains a method called onCreate and it has a few lines of code in it. Unfortunately it doesn't do exactly what I want it to do.

In my MainActivity, by using @override on onCreate I can make changes to the onCreate method so it's my own customised version of what was in AppCompatActivity.