method overriding

 Method is a collection of statements that perform some specific task and return the result. Override means two methods having same name but doing different tasks. It means that one of the methods overrides another method. If there is any method in the superclass and a method with the same name in its subclass, then by executing these methods, method of the corresponding class will be executed.



# Ruby program of method overriding
 
# define a class
class A  
  def a  
    puts 'Geeks'  
  end  
end  
 
# define a subclass  
class B < A  
 
  # change existing a method as follows
  def a  
    puts 'Welcome to GeeksForGeeks'  
  end  
end  
    
b = B.new  
b.a  


...........................................


Comments

Popular posts from this blog

Rails 7 Features :: Comparison with Rails 6 and Rails 5