zoukankan      html  css  js  c++  java
  • 多态

    概念

    // 必须有继承关系                                                                                                                        

    // 2 父类指针指向子类对象(一个对象的多种形态)

    // 3 动态绑定:在运行过程中,把student这种真实类型绑定到Person类型的指针上           

     

    例子1

    #import <Foundation/Foundation.h>

    #import "Person.h"

    #import "Student.h"

    int main(int argc, constchar * argv[]) {

     

        // 1 必须有继承关系

        // 2 父类指针指向子类对象(一个对象的多种形态)

        // 3 动态绑定:在运行过程中,把student这种真实类型绑定到Person类型的指针上

        

        Student *s = [Studentnew];     // Student类型

        

        Person *s1 = [Studentnew];      // Person类型

        return 0;

    }

     
     
    #import <Foundation/Foundation.h>                                                     

    @interface Person : NSObject

    {

        int  _age;

        char *_name;

    }

    @end

     

    #import "Person.h"

    @implementation Person

    @end

     

    #import "Person.h"

    @interface Student : Person

    @end

     

    #import "Student.h"

    @implementation Student

    @end

  • 相关阅读:
    sql查询
    PHP常用的设计模式
    PHP内存管理和垃圾回收机制
    记一次面试
    获取py文件函数名及动态调用
    正确解决 mysql 导出文件 分隔符 问题
    解决ValueError: cannot convert float NaN to integer
    Python ---接口返回值中文编码问题
    pandas python 读取大文件
    【neo4J】后台关闭后,前端还能打开视图
  • 原文地址:https://www.cnblogs.com/GhostKZShadow/p/5105196.html
Copyright © 2011-2022 走看看