Method Overriding in Java
This post is Part 5 of Inheritance in Java series of articles. The series explains inheritance in Java in detail. This part explains method overriding and its relation with inheritance. It is suggested you first read the basics of inheritance which is explained in Part 1 to Part 4. When we inherit a class from another class, its methods and attributes are inherited based on their access modifiers. Method overriding is a concept of redefining an inherited method in the child class . When we redefine a method in child class to override; its name, list of arguments with order and types should be same as defined in the parent class. The return type in the child class must be same as, or a subtype of, the return type defined in parent class. After overriding, when we create an object of child class and call the overridden method, the method of child class would be executed instead of parent class. Lets see it working using in Shape and Rectangle classes. package com.bitspedia; pu...