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
  • 相关阅读:
    一. js高级(1)-面向对象编程
    tips01- 定位
    h5c3 part6 flex
    h5c3 part5 background and transform
    template and pagination
    h5c3 part4
    h5c3 part3
    h5c3 part2
    h5c3 part1
    学习博客
  • 原文地址:https://www.cnblogs.com/liuwj/p/6899685.html
Copyright © 2011-2022 走看看