Basics of method overriding in Java

Method Overriding in JAVA



  • The process of changing the body of the methods inherited from the parent class to the child class is called method override. For a method to be overridden, the class must be inherited. 



    

  • As we said earlier, in order to override, both the parent and child classes must have methods with the same name. When a class is inherited, the child class automatically inherits the contents of the parent class.
  • After that, two methods will be created in the child class with the same name(the inherited method and the overridden method).



  • When the method is overridden, usually only the method of the child class is executed. The method of the inherited class will never be run.
  • If we need to run parent class method in child class, we have another concept for it. Lets see about it in next blog.





Comments

Popular posts from this blog

අද අපි කතා කරමු Data collections ගැන

Understanding and Mastering Coding Errors

OOP key points