Pages

Friday, December 31, 2010

Inheritance in Ruby [circle triangle ,square]

class Shapes
def triangle (b,h)
t=(b*h)/2
print "triangle=#{t}"
end

def circle(r)
c=(3.14)*r*r
print "circle =#{c}"
end

def square(a)
s = a*a
print "square=#{s}"
end
end

class Compute < Shapes
end
area = Compute.new
area.triangle(2,5)
puts
area.circle(5)
puts
area.square(6)
puts

No comments:

Post a Comment