@implementation Square
- (void)calculateAreaOfSide:(CGFloat)side
{
area = side * side;
}
- (void)printArea
{
NSLog(@"The area of square is %f",area);
}
2013-09-28 07:42:29.821 demo[4916] The area of square is 100.000000
2013-09-28 07:42:29.821 demo[4916] The area of Rectangle is 50.000000
正如可以看到在上面的例子中,printArea 方法是在运行时动态选择。这是一个动态绑定的例子,在同类对象打交道时情况下是非常有用。