Inheritance
Inheritance is a relation between two classes. A child class inherits all the features of its parent class. Methods from the parent can be overridden in the child and new logic can be added.
Usually, inheritance is used to specialize a class. See the following example :
class Document
def initialize; end
# logic to deal with any document
def print
# logic to print any kind of document
end
end
—
class XmlDocument < Document
# logic to deal with any document
def print
# logic to print a xml document
end
end
A class can only inherit from one class as opposed to c++ where multi-inheritance can be done (not always for the better).