zoukankan      html  css  js  c++  java
  • OC6_类方法

    //
    //  Dog.h
    //  OC6_类方法
    //
    //  Created by zhangxueming on 15/6/9.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @interface Dog : NSObject
    {
        NSString *_name;
        NSInteger _age;
    }
    
    + (id)dogCreate;
    
    - (NSString *)name;
    - (NSInteger)age;
    
    - (void)setName:(NSString *)name andAge:(NSInteger)age;
    
    @end
    //
    //  Dog.m
    //  OC6_类方法
    //
    //  Created by zhangxueming on 15/6/9.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "Dog.h"
    
    @implementation Dog
    
    + (id)dogCreate
    {
        Dog *dog = [[Dog alloc] init];
        return dog;
    }
    
    - (NSString *)name
    {
        return _name;
    }
    
    - (NSInteger)age
    {
        return _age;
    }
    
    - (void)setName:(NSString *)name andAge:(NSInteger)age
    {
        _name = name;
        
        _age = age;
    }
    
    @end
    //
    //  main.m
    //  OC6_类方法
    //
    //  Created by zhangxueming on 15/6/9.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import "Dog.h"
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            
            Dog *xiaoBai = [Dog dogCreate];
            
             //Dog *dog = [[Dog alloc] init];
    
            
            [xiaoBai setName:@"小白" andAge:12];
            NSLog(@"name = %@ age = %li", [xiaoBai name], [xiaoBai age]);
        }
        return 0;
    }
  • 相关阅读:
    gcc/g++命令参数笔记
    周总结
    帆软FineBI试用
    C++输入流
    tt
    linux6 安装oracle11g
    linux下修改/dev/shm tmpfs文件系统大小
    centos6.5_x86_64 下安装 Oracle11gR2 的详细过程
    Linux Network配置
    安装KornShell(KSH)
  • 原文地址:https://www.cnblogs.com/0515offer/p/4564302.html
Copyright © 2011-2022 走看看