Ruby is a object oriented programming language , it support to provide a specific implementation to the methods of subclasses that is already defined in superclasses . If there is any method in subclasses is same as the method of superclass then subclass method override it.
Example :
class Vehicle
def bmw
puts "my bmw"
end
end
class Car < Vehicle
def bmw
puts "override bmw"
end
end
c = Car.new
c.bmw
v = Vehicle.new
v.bmw
Output :
c = Car.new
c.bmw
override bmw
v = Vehicle.new
v.bmw
my bmw
0 Comment(s)