首页 > 代码库 > Objective-C的第二课
Objective-C的第二课
今天学习了继承, 属性, 多态
作业:动物父类, 猫科子类, 狮子孙子类;
#import <Foundation/Foundation.h>@interface Animal : NSObject@end //动物类#import <Foundation/Foundation.h>@interface Animal : NSObject@end //动物类#import "Animal.h"@interface Feline : Animal- (void)eyes;- (void)tail;- (void)flid;@end //猫科动物类#import "Animal.h"@interface Feline : Animal- (void)eyes;- (void)tail;- (void)flid;@end //猫科动物类#import "Feline.h"@interface Lion : Feline- (void)character;- (void)body;@end //狮子类#import "Lion.h"@implementation Lion- (void)character{ NSLog(@"%@", @"Lion character fierce and cruel"); //性格凶残}- (void)body{ NSLog(@"%@", @"Lion A strong"); //身体强壮}@end //狮子类#import "ViewController.h"#import "Lion.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. Animal *animal; Feline *feline; //定义对象 feline = [[Feline alloc] init]; //初始化 [feline flid]; //打印行为 [feline eyes]; [feline tail]; [feline release]; Lion *lion; lion = [[Lion alloc] init]; [lion character]; [lion body]; }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
Objective-C的第二课
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。