Friday, March 7, 2014

Why android often call super () function?


For example
 
public boolean onOptionItemSelected (MenuItem item) {
return super.onOptionsItemSelected (item);
}


Yes, java syntax a bit rusty, ask why you want to call the parent class? Why do not you call your own?<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Inherited from the parent class, you can call the parent class with a super way to achieve the function of the parent class method, the method of adding
want to achieve your own
Reply:
The method of the parent class may be necessary to achieve the basic operation of the sub-class is done for other functions in operating on the basis of these basic
Reply:
This parent class method has achieved what features we need, we own these features may be unattainable. Like the back button callback function, this callback when you rewrite, if you both want him to have the new features, and want to be able to achieve returns. For example, we want to press the back key to exit the program, you are prompted to quit before the launch, we have to call back button callback parent class, that is, through the super keyword to call the parent class method, so as to achieve the return of function, and Our newly added feature is a pop-up prompt dialog box. Here, back button to return to the function is not a simple software program, but also to respond to the hardware circuit, is difficult to achieve. This is why you want to use the super keyword to call the parent class's reasons for this approach.
Reply:
Thank you. Probably understand.
Reply:
I am a novice, I think weak weak to ask a parent class that I inherited, that I do not have a parent class functionality why it is called a
Reply:
Found many cases, the parent class method turned out to be abstract, there is no concrete realization. In the sub-category which call super, I do not know where to call to achieve?

Very strange java
Reply:
references, 5th Floor qqOuKe reply:
my beginner I think weak weak to ask a parent class that I inherited, that I do not have a parent class functionality Why it is called once


I do not really understand, I guess.
Inheritance is to have the function of the parent class.
However, after rewriting function, there is no corresponding function. So, to re-call the next.

No comments:

Post a Comment