oc-18-继承
2016-03-23 10:17
246 查看
//Animal.h #import <Foundation/Foundation.h> @interface Animal : NSObject { int _age; // 不写@public,默认只能在本类和子类当中访问.间接继承. } @end //Animal.m #import "Animal.h" @implementation Animal { int _weight; // 写在.m文件中的成员变量,叫做私有成员变量.只能在本类当中访问,子类不能访问或者设置 } @end //Dog.h #import "Animal.h" @interface Dog : Animal - (void)lookHome; @end //Dog.m #import "Dog.h" @implementation Dog - (void)lookHome { _age = 1; // _weight = 9; // 私有变量,子类不能访问或者设置 NSLog(@"看家......"); } @end
.h文件中子类父类不能定义同名的变量,.m文件中子类父类可以有相同的变量名。
super调用的直接父类,直接父类没有就是爷爷类。super在对象方法中只能调用父类的对象方法,在类方法中只能调用父类的类方法。
相关文章推荐
- 需要记住的的资料网址
- (转)STORM启动与部署TOPOLOGY
- Linux c日志打印
- 写博客记住自己忘记的东西
- I/O Completion Ports(完成端口)
- 使用fuel部署openstack时遇到的问题记录一下
- 深入Protobuf源码-概述、使用以及代码生成实现
- jQuery对象与dom对象
- 微信JS-SDK实现自定义分享功能,分享给朋友,分享到朋友圈,后台实现
- android实现开机自动启动Service或app
- 计算机OS是如何运行程序的
- ReactNative列表ListView
- Android屏蔽Home键、屏蔽下拉菜单最有效的办法(部分手机无效)
- 转:FORM:客制化Form的菜单栏和右鍵菜單
- js倒计时
- linux yum命令详解
- Android ViewPager+Fragment滑动选项卡,tab点击选项卡
- Application的onCreate方法被调用多次的问题
- iOS面试题
- 为什么年龄越大越不容易恋爱?