Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Ruby Overriding

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 181
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: