首页 > 代码库 > 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的第二课