开发者

Significance of Super?

Can anybody tell me why we need the s开发者_如何学JAVAuper in every method for e.g.:

-(void)viewDidLoad
{
    [super viewDidLoad];
}

I am confused about the super keyword....


[super ...] calls the implementation of the method in your class's superclass. It is important to use if the inheriting class wants to extend the method implementation (i.e., add something to it but also do what the superclass did) as opposed to replacing the method implementation.

As such, you do not call super in every method you override but only where it is appropriate. If you should, must or must not call super in a specific method should be mentioned in the documentation of that method.


To call the method of the parent class.

This is the rule when you override the method of the superclass, so that you can make sure that code in the superclass get executed and behave correctly.

Note: Sometimes, you call super in the beginning of the method, some other times, in the end of the method

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜