zoukankan      html  css  js  c++  java
  • OC 类 的声明


           

               Student.h

    // @interface代表声明一个类
    // : 代表继承
    @interface Student : NSObject { // 成员变量要定义在下面的大括号中{}
        int age;
        int no;
    }
    
    // 在这里声明的所有方法都是公共
    
    // age的get方法
    // - 代表动态方法  + 代表静态方法
    - (int)age;
    
    // age的set方法
    - (void)setAge:(int)newAge;
    
    // no的get方法
    - (int)no;
    
    - (void)setAge:(int)newAge andNo:(int)newNo;
    @end
    #import "Student.h"
    
    @implementation Student
    
    - (int)age {
        NSLog(@"调用了getAge方法");
        return age;
    }
    
    - (void)setAge:(int)newAge {
        age = newAge;
        
        NSLog(@"调用了setAge方法");
    }
    
    - (int)no {
        return no;
    }
    
    - (void)setAge:(int)newAge andNo:(int)newNo {
        age = newAge;
        no = newNo;
    }
    @end
  • 相关阅读:
    08--Docker安装Mysql
    第三天
    html---Keymaker-EMBRACE
    解析selenium http://blog.csdn.net/java2000_net/article/details/3721706
    selenium
    day4复习
    函数
    列表
    int整数和bool值
    字符串方法整理
  • 原文地址:https://www.cnblogs.com/liuwj/p/6899685.html
Copyright © 2011-2022 走看看