A class can have an inheritance relation with a super class. The sub class inherits all the attributes and methods from the super class.
If an object is created using a sub class, it has the methods and attributes of both the sub class and the super class. You can have multiple sub classes that inherit from the same super class.
The ruby program below creates an object with the defined sub class.
The above program defines a super class: Bird. Then a sub class is defined (parrot). The sub class inherits all attributes and methods from the super class.
Finally we create an object. The object has both the methods and attributes of the super class and the sub class.
- Can a class inherit from 2 super classes?
- Can super classes inherit from other super classes?
- Add another class that inherits from the super class bird.