#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的更多相关文章

  1. Automake

    Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...

  2. C++ vs Objective C

    oc Short list of some of the major differences: C++ allows multiple inheritance, Objective-C doesn't ...

  3. Replace conditional with Polymorphism

    namespace RefactoringLib.Ploymorphism.Before { public class Customer { } public class Employee : Cus ...

  4. Objective C中的ARC的修饰符的使用---- 学习笔记九

    #import <Foundation/Foundation.h> @interface Test : NSObject /** * 默认的就是__strong,这里只是做示范,实际使用时 ...

  5. Objective的字符串拼接 似乎没有Swift方便,但也可以制做一些较为方便的写法

    NSString *str1 = @"字符串1"; NSString *str2 = @"字符串2"; //在同样条件下,Objective的字符串拼接 往往只 ...

  6. TIJ——Chapter Eight:Polymorphism

    The twist |_Method-call binding Connecting a method call to a method body is called binding. When bi ...

  7. [转] 从 C 到 Objective C 入门1

    转自: http://blog.liuhongwei.cn/iphone/objective-c/ 进军iPhone开发,最大的难点之一就是怪异的Objective C语法了.不过,了解之后才发现,原 ...

  8. Objective C运行时(runtime)

    #import <objc/runtime.h> void setBeingRemoved(id __self, SEL _cmd) { NSLog(@"------------ ...

  9. Objective C ARC 使用及原理

    手把手教你ARC ,里面介绍了ARC的一些特性, 还有将非ARC工程转换成ARC工程的方法 ARC 苹果官方文档 下面用我自己的话介绍一下ARC,并将看文档过程中的疑问和答案写下来.下面有些是翻译,但 ...

  10. Scalaz(2)- 基础篇:随意多态-typeclass, ad-hoc polymorphism

    scalaz功能基本上由以下三部分组成: 1.新的数据类型,如:Validation, NonEmptyList ... 2.标准scala类型的延伸类型,如:OptionOps, ListOps . ...

随机推荐

  1. javascript 中关于对象转换数字值的一些特点

    下面是摘至<Javascript 高级程序设计第三版>里的一段话 是关于对象转换数字值的一些规则 "在应用于对象时,先调用对象的valueOf()方法以取得一个可供操作的值.然后 ...

  2. crossplatform---Nodejs in Visual Studio Code 08.IIS

    1.开始 本文部分内容均转载自文章: http://www.hanselman.com/blog/InstallingAndRunningNodejsApplicationsWithinIISOnWi ...

  3. paip兼容windows与linux的java类根目录路径的方法

    paip兼容windows与linux的java类根目录路径的方法 1.只有 pathx.class.getResource("")或者pathx.class.getResourc ...

  4. Apache JMeter 测试Http请求

    环境安装:JDK 下载:http://jmeter.apache.org/download_jmeter.cgi 启动: 简单HTTP请求测试

  5. web前端基础——初识HTML DOM编程

    1 HTML DOM编程概述 文件对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理HTML的标准编程接口.由于HTML文档被浏览器解析后就是一棵DOM树,要改 ...

  6. Python之线程池

    版本一: #!/usr/bin/env python # -*- coding:utf-8 -*- import Queue import threading class ThreadPool(obj ...

  7. python连接数据库

    使用pymysql://安装pymysqlpip install pymysql 代码: # coding=utf8 import pymysql # 创建连接对象 conn = pymysql.co ...

  8. this和super用法的总结

    在学习this和super关键字时,发现它们有诸多相同点,同时这两个关键字非常常用,现对它们做以下的总结. 一.概况 This: This指代当前对象,this()指代当前对象的其他构造函数 Supe ...

  9. Xamarin.Forms bug? System.ObjectDisposedException: Cannot access a disposed object

    Hi, My Android Xamarin.Forms application uses a Navigation stack to display various views, I often h ...

  10. 学习Swift,一定不能错过的10大开源项目!

    如果你是位iOS开发者,或者你正想进入该行业,那么Swift为你提供了一个绝佳的机会.Swift的设计非常优雅,较Obj-C更易于学习,当然也非常强大. 为了指导开发者使用Swift进行开发,苹果发布 ...