Objective-C Polymorphism
#import <Foundation/Foundation.h> @interface Shape : NSObject
{
CGFloat area;
}
-(void)printArea;
-(void)calculateArea;
@end @implementation Shape -(void)printArea {
NSLog(@"The area is %f",area);
} -(void)calculateArea {
} @end @interface Square : Shape
{
CGFloat length;
} -(id)initWithSide : (CGFloat)side;
-(void)calculateArea; @end @implementation Square -(id)initWithSide : (CGFloat)side {
length = side;
return self;
} -(void)calculateArea {
area = length * length;
} -(void)printArea {
NSLog(@"The area of square is %f", area);
} @end @interface Rectangle : Shape
{
CGFloat length;
CGFloat breadth;
}
-(id)initWithLength: (CGFloat)rLen andBreadth:(CGFloat)rBreadth; @end @implementation Rectangle -(id)initWithLength: (CGFloat)rLen andBreadth:(CGFloat)rBreadth {
length = rLen;
breadth = rBreadth;
return self;
} -(void)calculateArea {
area = length * breadth;
} -(void)printArea {
NSLog(@"The area of Rectangle is %f", area);
} @end int main(int ar, const char * argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
Shape *square = [[Square alloc]initWithSide:4.2];
[square calculateArea];
[square printArea];
Shape *rect = [[Rectangle alloc]initWithLength:7.88 andBreadth:6.35];
[rect calculateArea];
[rect printArea]; [pool drain];
return ; }
Objective-C Polymorphism的更多相关文章
- Automake
Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...
- C++ vs Objective C
oc Short list of some of the major differences: C++ allows multiple inheritance, Objective-C doesn't ...
- Replace conditional with Polymorphism
namespace RefactoringLib.Ploymorphism.Before { public class Customer { } public class Employee : Cus ...
- Objective C中的ARC的修饰符的使用---- 学习笔记九
#import <Foundation/Foundation.h> @interface Test : NSObject /** * 默认的就是__strong,这里只是做示范,实际使用时 ...
- Objective的字符串拼接 似乎没有Swift方便,但也可以制做一些较为方便的写法
NSString *str1 = @"字符串1"; NSString *str2 = @"字符串2"; //在同样条件下,Objective的字符串拼接 往往只 ...
- TIJ——Chapter Eight:Polymorphism
The twist |_Method-call binding Connecting a method call to a method body is called binding. When bi ...
- [转] 从 C 到 Objective C 入门1
转自: http://blog.liuhongwei.cn/iphone/objective-c/ 进军iPhone开发,最大的难点之一就是怪异的Objective C语法了.不过,了解之后才发现,原 ...
- Objective C运行时(runtime)
#import <objc/runtime.h> void setBeingRemoved(id __self, SEL _cmd) { NSLog(@"------------ ...
- Objective C ARC 使用及原理
手把手教你ARC ,里面介绍了ARC的一些特性, 还有将非ARC工程转换成ARC工程的方法 ARC 苹果官方文档 下面用我自己的话介绍一下ARC,并将看文档过程中的疑问和答案写下来.下面有些是翻译,但 ...
- Scalaz(2)- 基础篇:随意多态-typeclass, ad-hoc polymorphism
scalaz功能基本上由以下三部分组成: 1.新的数据类型,如:Validation, NonEmptyList ... 2.标准scala类型的延伸类型,如:OptionOps, ListOps . ...
随机推荐
- atitit.文件上传带进度条的实现原理and组件选型and最佳实践总结O7
atitit.文件上传带进度条的实现原理and组件选型and最佳实践总结O7 1. 实现原理 1 2. 大的文件上传原理::使用applet 1 3. 新的bp 2 1. 性能提升---分割小文件上传 ...
- iOS开发----调用地图导航
注意:本文章下的代码有个别变量未知,所以是不能直接跑通的,我也是转别人的 在IOS6.0系统后,兼容iOS5.0与iOS6.0地图导航,需要分两个步骤 #define SYSTEM_VERSION_L ...
- php类自动装载、链式操作、魔术方法
1.自动装载实例 目录下有3个文件:index.php load.php tests文件夹 tests文件夹里有 test1.php <?php namespace Tests; class T ...
- 18数据表&E-R模型&概念数据模型-下(选学)-天轰穿大话数据库视频教程
关键字:数据表 三大范式 外键 主键 数据表设计 天轰穿 sqlserver 数据库大纲:属性与主键,外键&联系,三大范式,设计表时应该考虑的因素 土豆超清地址: 优酷超清地址: 原文地址:h ...
- .net下BerkeleyDB操作封装C#版(附单元测试)
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System ...
- Mac Port 基本用法总结
Mac Port 基本用法总结 Mac Port 基本用法总结 1. Mac Port的下载地址 http://www.macports.org/install.php 2. Mac Port的说明文 ...
- ubuntu下安装Node.js(源码安装)
最近使用hexo的过程中出现了问题,中间载nodejs安装的时候也耽误了些许时间,所以在此记录一下安装的过程. 环境:ubuntu14.0.4LTS,安装nodejs版本node-v0.10.36.t ...
- android设置背景半透明效果
1.Button或者ImageButton的背景透明或者半透明 半透明:<Button android:background="#e0000000"···> 透明:&l ...
- <a>标签href属性与onclick事件
a标签主要用来实现页面跳转,可以通过href属性实现,也可以在onclick事件里实现. <a onclick="window.location.href='www.cnblogs.c ...
- LCLFramework框架 1.1 Pre-Alpha 源码公布
使用开发框架的好处:1.框架在技术上为软件系统提供了完整的模式实践2.框架为团队提供了合理可行的软件开发过程模式3.框架的应用大大提高了团队的开发效率,团队只需要关注与领域相关的业务实现,而无需关注具 ...