1

I have a question about Androids onCreate method. I understand that the Activity is extended and that onCreate() is implemented as android developers guide states (Class Overview at http://developer.android.com/reference/android/app/Activity.html). But why do we use @Override? And also if i want to refer to that method what word should i use? Should i say that onCreate() is Overrided or that onCreate() is implemented ?

 public class MainActivity extends Activity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
     }
duggu
  • 37,851
  • 12
  • 116
  • 113
user2713459
  • 49
  • 2
  • 5

3 Answers3

2

onCreate is "Overridden" because Activity has an existing implementation that your class MainActivity is replacing with it's own implementation. you would say "implemented" if the method is only declared in an interface, but there is no implementation in a super class your are replacing.

the annotation @Override is an optional (but recommanded) hint for the compiler that the following method signature must exists in the super class or interface your are extending. It will result in an compile error if this is not the case. It's also a hint for the developer that this method also exists in the super class.

Simulant
  • 19,190
  • 8
  • 63
  • 98
1

@Override is an annotation that will throw a compilation error if the signatures of the methods don't match (for example if you omit the parameter savedInstanceState) and that's how an overridden method is marked.

Furthermore the method is not implemented because it already has an implementation in Activity (which is called by super.onCreate(savedInstanceState) ) it is overridden

Did I answer your question?

Vlad Ilie
  • 1,389
  • 1
  • 13
  • 37
0

you have to override that Method because it isn't directly implemented in the superclass. You can say 'It's overridden'.

Sasukex3
  • 31
  • 3