Skip to content

Ruby Class:Day9 Inheritance

31/12/2010

This day start with Rmagic calendar program try solution not reach..
Then start Ducktyping Inheritance concept..
simple task of inheritance
computing area of circle,triangle,square

class Shape
  def circle(radius)
    cir=3.14*radius*radius
  end
  def triangle(bash,height)
    tri=0.5*bash*height
  end
  def square(length,breath)
    squ=length*breath
  end
end
class Shapecal < Shape
  def get_input
    print "enter the radius:"
    radius=gets.chomp.to_i
    print "Enter the bash,height for triangle:"
    bash=gets.chomp.to_i
    height=gets.chomp.to_i
    print "Enter the length,breath of square:"
    length=gets.chomp.to_i
    breath=gets.chomp.to_i    
    print "Area of circle:",circle(radius)
    print "\nArea of triangle:",triangle(bash,height)
    print "\nArea of square:",square(length,breath),"\n"
  end
end
cal=Shapecal.new
cal.get_input

from this program i learn how to inherit sub class from super class.
and access it….

Wish you a happy new year friends……..

Advertisements

From → Ruby

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: