You want to create an abstract base class Shape with an abstract method area. Then, create two subclasses Circle and Square that implement area. Which code correctly achieves this?
hard📝 Application Q15 of 15
Python - Polymorphism and Dynamic Behavior
You want to create an abstract base class Shape with an abstract method area. Then, create two subclasses Circle and Square that implement area. Which code correctly achieves this?
Afrom abc import ABC
class Shape(ABC):
def area(self):
pass
class Circle(Shape):
def area(self):
return 3.14 * self.r ** 2
class Square(Shape):
def area(self):
return self.s * self.s