From 531eba99bc4d2af0b1d7819986985ac2e9f78bfa Mon Sep 17 00:00:00 2001 From: BHARAT KUMAR PRAJAPAT <123304396+bharatprajapat014@users.noreply.github.com> Date: Tue, 14 Feb 2023 10:50:47 +0530 Subject: [PATCH] Create Polymorphism --- OOP/Polymorphism | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 OOP/Polymorphism diff --git a/OOP/Polymorphism b/OOP/Polymorphism new file mode 100644 index 0000000..ee47ed5 --- /dev/null +++ b/OOP/Polymorphism @@ -0,0 +1,44 @@ +from math import pi + + +class Shape: + def __init__(self, name): + self.name = name + + def area(self): + pass + + def fact(self): + return "I am a two-dimensional shape." + + def __str__(self): + return self.name + + +class Square(Shape): + def __init__(self, length): + super().__init__("Square") + self.length = length + + def area(self): + return self.length**2 + + def fact(self): + return "Squares have each angle equal to 90 degrees." + + +class Circle(Shape): + def __init__(self, radius): + super().__init__("Circle") + self.radius = radius + + def area(self): + return pi*self.radius**2 + + +a = Square(4) +b = Circle(7) +print(b) +print(b.fact()) +print(a.fact()) +print(b.area())