来啦,已经跑了好几圈啦....
Canvas is not supported in your browser.

ruby的实例变量

class Box
  def initialize(w,h)
    @width,@height=w,h
  end
  def getArea
    @height*@width
  end
end
class BigBox <Box
  def printArea
    @area=@width*@height
    puts "#@area"
  end
  def getArea
    puts "bigbox 的面积是 #@area "
  end
end
box =BigBox.new(12,12)
box.printArea//只有加上这个,area才有值
box.getArea

 

posted @ 2019-05-07 14:18  fangpengcheng_方鹏程  阅读(175)  评论(0编辑  收藏  举报