#!/usr/bin/ruby -w
# 定义类
class Box
# 构造器方法
def initialize(w,h)
@width, @height = w, h
end
# 实例方法
def getArea
@width * @height
end
end
# 定义子类
class BigBox < Box
# 改变已有的 getArea 方法
def getArea
@area = @width * @height
puts "Big box area is : #@area"
end
end
# 创建对象
box = BigBox.new(10, 20)
# 使用重载的方法输出面积
box.getArea()