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

  • 相关阅读:
    大数乘法的几种算法分析及比较(2014腾讯南京笔试题)
    【经典数据结构】Trie
    [LeetCode] MaximumDepth of Binary Tree
    [LeetCode] Minimum Depth of Binary Tree
    二叉树相关题目总结
    python之函数基础总结
    python基础之文件处理总结
    利用for循环和range输出9 * 9乘法口诀表
    购物车程序作业
    字典练习
  • 原文地址:https://www.cnblogs.com/GhostKZShadow/p/5105196.html
Copyright © 2011-2022 走看看