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 . ...
随机推荐
- python __str__ & __repr__ & __cmp__
For ( __str__ ),we going to see a example ... and find who is working for ... #!/usr/bin/python clas ...
- Javascript提升阶段学习
JavaScript1:javascript简介 JavaScript是一种脚本语言,能实现网页内容的交互显示,当用户在客户端显示该网页时,浏览器就会执行JavaScript程序,用户通过交互的操作来 ...
- Python之线程池
版本一: #!/usr/bin/env python # -*- coding:utf-8 -*- import Queue import threading class ThreadPool(obj ...
- HtmlDocument
HtmlDocument HtmlDocument类对应着一个HTML文档代码.它提供了创建文档,装载文档,修改文档等等一系列功能,来看看它提供的功能. 一.属性 int CheckSum { get ...
- LoadRunner 如何将英文的字符串转换成UTF-8格式的字符串?
7.48 如何手动转换字符串编码 1.问题提出 如何将英文的字符串转换成UTF-8格式的字符串? 2.问题解答 可以使用lr_convert_string_encoding函数将字符串从一种编码手动 ...
- 转:RTMPdump使用相关
在FFMPEG中使用libRTMP的经验 FFMPEG在编译的时候可以选择支持RTMP的类库libRTMP.这样ffmpeg就可以支持rtmp://, rtmpt://, rtmpe://, rtmp ...
- 阿里云产品介绍(一):云服务器ECS
最近天南海北的跑客户,在沟通过程中,发现很多客户对于阿里云众多的产品颇有种挑花了眼不知如何入手的感觉,就想写一个系列来简单的介绍下. 云计算的概念刚出来的时候,吹的牛皮是可以将成千上万台物理服务器连接 ...
- Javacript和AngularJS中的Promises
promise是Javascript异步编程很好的解决方案.对于一个异步方法,执行一个回调函数. 比如页面调用google地图的api时就使用到了promise. function success(p ...
- LeetCode:Container With Most Water,Trapping Rain Water
Container With Most Water 题目链接 Given n non-negative integers a1, a2, ..., an, where each represents ...
- Windows下Nginx的安装与配置(转)
一.首先去官网下载 nginx1.0.11的Windows版本,官网下载:http://nginx.org/download/nginx-1.0.11.zip 下载到软件包后,解压 nginx-ngi ...