Program not running (Overloading problem) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Program not running (Overloading problem) (/thread-8416.html) |
Program not running (Overloading problem) - anurag123 - Feb-19-2018 class Area(object): def get_area(self): return("WORKING FINE") class Rectangle(Area): def get_area(self,l,b): self.l=l self.b=b return (self.l*self.b) class Circle(Rectangle): def get_area(self,r): self.r=r return (3.14*self.r*self.r) obj=Circle() print(obj.get_area()) print(obj.get_area(6,3)) RE: Program not running (Overloading problem) - Larz60+ - Feb-19-2018 obj.get_area requires an argument, r, and only one so format would be obj.get_area(10) for example I don't know why you call it overloading, as you are not overloading anything. You only overload a class when yo are going to change the operation of one or more of the methods, and that is done thusly: import myclass class circle(myclass): RE: Program not running (Overloading problem) - nilamo - Feb-19-2018 Unrelated, but why is Circle extending Rectangle? They're very different, unrelated things, and anything that they might happen to share would be in the base Area class. |