0
What's the advantages of using classes instead of methods..
Hello friends... Im just wondering of comprehending the advantages of using classes instead of methods... I've just wrote a couple lines of code to calculate the area of rectangle by using both, the classes n methods concepts.. but as its clear, using methods is simple n shorter than classes so, what makes sense of using classes instead of methods...
1 Answer
+ 1
Here is my simple code đđ
class Box
def initialize(w, h)
@width = w
@height = h
end
def area
@width * @height
end
end
p1 = Box.new(gets.to_i, gets.to_i )
puts p1.area
puts "===============++++================"
def calArea (w, h)
print w*h
end
puts calArea(gets.to_i, gets.to_i)