Subclasses

suggest change

Inheritance allows classes to define specific behaviour based on an existing class.

class Animal
  def say_hello
    'Meep!'
  end

  def eat
    'Yumm!'
  end
end

class Dog < Animal
  def say_hello
    'Woof!'
  end
end

spot = Dog.new
spot.say_hello # 'Woof!'
spot.eat       # 'Yumm!'

In this example:

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents