iOS开发方法重写

2019-08-21  本文已影响0人  Silence_xl
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface Girl : NSObject

-(void) play;

@end

NS_ASSUME_NONNULL_END
#import "Girl.h"

@implementation Girl

//方法的实现
-(void) play
{
    NSLog(@"好好的玩!");
}

@end
#import "Girl.h"

NS_ASSUME_NONNULL_BEGIN

@interface BeautifulGirl : Girl

@end

NS_ASSUME_NONNULL_END
#import "BeautifulGirl.h"

@implementation BeautifulGirl

//重写方法
-(void) play
{
    NSLog(@"佳人更好玩!");
}

@end
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "BeautifulGirl.h"
#import "Girl.h"

int main(int argc, char * argv[]) {
    NSString * appDelegateClassName;
    @autoreleasepool {
        // Setup code that might create autoreleased objects goes here.
        appDelegateClassName = NSStringFromClass([AppDelegate class]);
        
    
        //创建BeautifulGirl对象
        Girl *gril = [[BeautifulGirl alloc] init];
        
        //执行对象的方法
        [gril play];
        
    }
    return UIApplicationMain(argc, argv, nil, appDelegateClassName);
}

image.png
image.png
image.png
image.png
上一篇 下一篇

猜你喜欢

热点阅读