zoukankan      html  css  js  c++  java
  • OC 方法和函数

    /*

     方法

     1.对象方法都是以减号 - 

     2.对象方法的声明必须写在@interface和@end之间

       对象方法的实现必须写在@implementation和@end之间

     3.对象方法只能由对象来调用

     4.对象方法归类对象所有

     函数

     1.函数能写在文件中的任意位置(@interface和@end之间除外),函数归文件所有

     2.函数调用不依赖于对象

     3.函数内部不能直接通过成员变量名访问某个对象的成员变量

     */

    #import <Foundation/Foundation.h>

    @interface Person : NSObject

    @end

    @implementation Person

    @end

    @interface Car : NSObject

    {// 成员变量实例变量

        //int wheels = 4; 不允许在这里初始化

        //static int wheels; 不能随便将成员变量当做C语言中的变量来使用

        @public

        int wheels;

    }

    - (void)run;

    - (void)fly;

    @end

    int main()

    {

        // wheels = 10;

        /*

        Car *c = [Car new];

        c->wheels = 4;

        //run();

        

        [c run];

        */

        

        void test2();

        

        test2();

        

        return 0;

    }

    @implementation Car

    - (void) fly

    {

        

    }

    /*

    void test2()

    {

        NSLog(@"调用了test2函数-%d", wheels);

    }*/

    void test()

    {

        NSLog(@"调用了test函数");

    }

    - (void)run

    {

        test();

        NSLog(@"%d个轮子的车跑起来了", wheels);

    }

    @end

  • 相关阅读:
    Jar包管理规范
    Base64编码原理与应用
    MySQL 5.7.14安装说明,解决服务无法启动
    idea注册
    Oracle 如何对中文字段进行排序
    SVN错误:Attempted to lock an already-locked dir
    排序算法
    设计模式
    分层
    阿里云
  • 原文地址:https://www.cnblogs.com/oc-bowen/p/5034381.html
Copyright © 2011-2022 走看看