zoukankan      html  css  js  c++  java
  • [Objective-c 基础

    A.继承的实现: is a

    1.不允许子类、父类存在相同的成员变量
    2.方法调用优先原则:子类调用方法的时候,优先从本类寻找,若无则向上在父类中寻找
    3.重写:子类重新实现父类的方法,覆盖父类之前的方法
    4.无论对象方法或类方法都可以重写
    5.缺点:致使耦合性增强
    6.OC只能单继承
     
    B.组合的实现: has
    1.不使用继承,而是将某个类作为成员变量,就可以使用其成员变量和方法
     
    C.super关键字
    对象方法和类方法都可以使用super调用父类的方法
     1 #import <Foundation/Foundation.h>
     2 
     3 @interface Zombie : NSObject
     4 - (void) walk;
     5 + (void) test;
     6 @end
     7 
     8 @interface JumpZombie : Zombie
     9 - (void) walk;
    10 + (void) test;
    11 @end
    12 
    13 @implementation Zombie
    14 - (void) walk
    15 {
    16     NSLog(@"往前挪两步");
    17 }
    18 
    19 + (void) test
    20 {
    21     NSLog(@"哈哈");
    22 }
    23 @end
    24 
    25 @implementation JumpZombie
    26 - (void) walk
    27 {
    28     NSLog(@"跳两下");
    29     [super walk];
    30 }
    31 
    32 + (void) test
    33 {
    34     NSLog(@"呵呵");
    35     [super test];
    36 }
    37 
    38 @end
    39 
    40 
    41 int main()
    42 {
    43     JumpZombie *jz = [JumpZombie new];
    44     [jz walk];
    45     [JumpZombie test];
    46     return 0;
    47 }
     
  • 相关阅读:
    【BZOJ 2440】[中山市选2011]完全平方数
    【BZOJ 1066】[SCOI2007]蜥蜴
    luogu P1317 低洼地
    luogu P1379 八数码难题
    luogu P1886 滑动窗口
    luogu P1032 字串变换
    题解 P1876 【开灯】
    题解 P1720 【月落乌啼算钱】
    题解 P2863 【[USACO06JAN]牛的舞会The Cow Prom】
    关于线性回归
  • 原文地址:https://www.cnblogs.com/hellovoidworld/p/4119351.html
Copyright © 2011-2022 走看看