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 . ...
随机推荐
- mysql 5.6.17 x64 安装
下载地址 百度网盘地址:http://pan.baidu.com/share/link?shareid=1895747668&uk=3257050114&fid=234538452 官 ...
- paip.java 线程无限wait的解决
paip.java 线程无限wait的解决 jprofl>threads>thread dump> 查看棉线程执行的code stack... 估计是.比如.BlockingQue ...
- Android JNI HelloWorld实现
创建一个JNIDemo的Android工程 在项目下创建一个文件夹jni.(注意必须是jni目录) 在jni目录下创建两个文件:Android.mk 和 first_jni.c(.c文件的名字可以任意 ...
- 报错:LINQ to Entities 不识别方法
大致是: var products = db.Products.Select(new ProductVm{Name=SomeMethod() }); 针对IQueryable集合的查询操作会被LINQ ...
- input type=file美化
最近碰到input type=file 之前用模拟点击来实现美化,发现在IE7下会有bug导致图片上传不上去,最后改用直接美化的方法 <!DOCTYPE html> <html la ...
- js弹出放大图
<script type="text/javascript"> function openpic(url){ OpenWindow = window.open(&quo ...
- Java线程与Linux内核线程的映射关系[转]
Linux从内核2.6开始使用NPTL (Native POSIX Thread Library)支持,但这时线程本质上还轻量级进程. Java里的线程是由JVM来管理的,它如何对应到操作系统的线程是 ...
- 10条现代EQ技术基础贴士(转)
前言: 无论是追求复古的模拟音色还是高精度的透明音质,现代电脑音乐制作中层出不断的新EQ插件以其超强的频率塑形和个性化功能为音色的润色和重塑提供了无限可能. 虽然EQ并不是音频工程工具中最复杂的,但是 ...
- Linux--Ubuntu12.04安装NDK
前言 本篇博客将介绍如何在Ubuntu12.04下安装Android NDK,在其他版本的Ubuntu下,方法也类似.由于Android NDK不能单独作为Android应用程序来运行,因此,使用An ...
- 持续集成工具Hudson安装实例
安装maven 下载maven,解压 [root@localhost local]# pwd /usr/local [root@localhost local]# -bin.tar.gz [root@ ...