Python Forum
Program not running (Overloading problem)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Program not running (Overloading problem)
#1
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))
Reply
#2
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):
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in running a code akbarza 7 541 Feb-14-2024, 02:57 PM
Last Post: snippsat
  Program running on RPi 3b+ Very Strange Behavior - Out of Bound Index MadMacks 26 3,050 Mar-07-2023, 09:50 PM
Last Post: MadMacks
  running a TensorFlow program Led_Zeppelin 0 880 Apr-07-2022, 06:33 PM
Last Post: Led_Zeppelin
  rtmidi problem after running the code x times philipbergwerf 1 2,396 Apr-04-2021, 07:07 PM
Last Post: philipbergwerf
  python to exe running problem Roshan 2 5,517 Mar-30-2021, 08:59 AM
Last Post: Roshan
  Python Program running a lot slower after change to Ubuntu hubenhau 1 2,838 Mar-02-2021, 05:01 PM
Last Post: Serafim
  Running Python 2.7 program ErnestTBass 2 2,713 Oct-21-2020, 08:06 AM
Last Post: snippsat
  read terminal text from running program AArdvark_UK 2 1,853 Aug-27-2020, 12:43 PM
Last Post: AArdvark_UK
  operator overloading won't work MaartenRo 1 1,780 Aug-04-2020, 02:37 AM
Last Post: deanhystad
  Modify code from running program ? samuelbachorik 2 2,406 Jun-26-2020, 08:17 PM
Last Post: samuelbachorik

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020