Method Overriding
Method Overriding
π¨βπΌ Now let's add methods to our shape hierarchy. Each shape will override a
method to provide its own implementation.
The
Shape, Circle, and Rectangle classes from the previous exercise are
already defined. You'll add and override the getArea() method.π¨ Open
and:
- Add a
getArea()method toShapethat returns 0 - Override
getArea()inCircleto return Ο Γ radiusΒ² - Override
getArea()inRectangleto return width Γ height