oc

#import "ViewController.h"
#import "Tiger.h"
#import "Lorry.h"


@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    Animal *animal =[[Animal alloc]init];
    [animal cry];
    Animal *cat =[[Cat alloc]init];
    [cat cry];
 
    [cat release];
    
    Animal *animal1 =[[Tiger alloc]init];
    [animal1 cry];
    [animal1 release];
    
    Transportation *lorry =[[Lorry alloc]init];
    [lorry run];
    [lorry release];
    Transportation *transportation1 =[[Car alloc]init];
    [transportation1 run];
    Transportation *transportation =[[Transportation alloc]init];
    [transportation run];
    

 现在对创建类与对象有一定的熟悉,同时明白如何用父类指针指向子类对象.大写是类,小写是累的对象,子类会有父类所有的方法和属性,即使在子类不声明,也可以调用,这叫继承,同事可以通过重新声明,来达到子类特有的一些方法与属性,类方法要用类名符号+,实例对象方法需要对象名,符号-.@pivate表示私有的,只能在这个类使用,其他类看不着,但是也会继承.@protect表示受保护的,只有他的子类可以读取,@public公共表示类外的也可以访问读取和需改.由于类文件太多,就上穿传一点了

#import "Tiger.h"

@implementation Tiger
- (void)cry
{
    NSLog(@"wo.....,%s",__PRETTY_FUNCTION__);
}

@end

#import "Cat.h"

@implementation Cat
- (void)cry
{
    NSLog(@"the cat  cry miao ,%s",__PRETTY_FUNCTION__);
}
@end
#import "Animal.h"

@implementation Animal
- (void)cry
{
    NSLog(@"some animal can cry and some can not cry, %s",__PRETTY_FUNCTION__);
}
@end

 

posted @ 2014-10-05 21:17  汪伟  阅读(325)  评论(0编辑  收藏  举报