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

  • 相关阅读:
    c语言中malloc函数的使用
    C语言的头文件和宏定义详解
    CUDA程序闪退时的处理方法【转】
    Shell面试,笔试整理
    阿里云系统安装部署Freeswitch
    汇编——根据偏移地址索取到的字数据
    一个典型的空语句(c,c++)
    关于64位系统的debug使用方法
    隐藏表单域、URL重写、cookie、session
    MVC的路由
  • 原文地址:https://www.cnblogs.com/GhostKZShadow/p/5105196.html
Copyright © 2011-2022 走看看