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 . ...
随机推荐
- C#:Oracle数据库带参PLSQL语句的正确性验证
在有Oracle数据库C#项目中,有一个这样的需求:在界面上配置了带参数的PLSQL语句,但是要通过程序验证其正确性,那么该如何实现?这就是本文要探讨的内容. 一:通过OracleCommand对象的 ...
- Linux中如何产生core文件?
在程序不寻常退出时,内核会在当前工作目录下生成一个core文件(是一个内存映像,同时加上调试信息).使用gdb来查看core文件,可以指示出导致程序出错的代码所在文件和行数. 1.core文件 ...
- thinkphp框架下404页面设置
404页面即系统在找不到请求的操作方法和找不到请求的控制器名称时的一种报错行为的优化. 第一步:在thinkphp框架中的Home/Comtroller中建一个EmptyController.clas ...
- 关于启明星系统移除apppath配置,让系统自动获取路径来设置cookie的解决方法
启明星系统底层使用统一接口,特别是用户,用户登录后,都会建立一个 userinfo 的cookie.请看下面2个网址: http://120.24.86.232/book http://120.24. ...
- SqlServer将没有log文件的数据库文件附加到服务器中
今天搞了一件很让我不爽的事情,一不小心把一个40多G的数据库日志文件删除,而且在删除之前我又搞了个日志进去,死活附加不了到服务器上去一直提示多个日志不能自动创建,白白浪费了我一个晚上的时间,后来不断的 ...
- ORA-01033:ORACLE initialization or shutdown in progress
借用他人的经验 客户Oracle服务器进入PL/SQL Developer时报ora-01033:oracle initializationg or shutdown in progress 错误提示 ...
- vs2013 下载
http://download.microsoft.com/download/2/4/9/249BF223-5B84-4259-9424-429E66F45509/VS2013_RC_ULT_CHS. ...
- WPF应用程序最小化到系统托盘
using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows; u ...
- JSP 处理汉字信息
request 对象获取客户端提交的汉字字符时,会出现乱码问题,所以对含有汉字字符的信息必须进行特殊处理.将获取的字符串用 ISO-8859-1 进行编码,并将编码存放到一个字节数组中,再将这个数组转 ...
- Codeforces Round #177 (Div. 1) 题解【ABCD】
Codeforces Round #177 (Div. 1) A. Polo the Penguin and Strings 题意 让你构造一个长度为n的串,且里面恰好包含k个不同字符,让你构造的字符 ...