different types of people : inheritance « Class « Ruby






different types of people

class Person
  def initialize(name)
    @name = name
  end

  def name
    return @name
  end
end

class Doctor < Person
  def name
    "Dr. " + super
  end
end

 








Related examples in the same category

1.Basing one class on another is called inheritance.
2.Extends class
3.how inheritance works in code form
4.Basing One Class on Another: a Demo
5.Structuring Your Pets Logically
6.If the class Name were in a different file, you would just require that file first
7.Add new constructor
8.Module and class hierarchy
9.Subclass Array class