Derived class inheriting from a base class. : Class Inheritance : Class PYTHON examples


PYTHON examples » Class » Class Inheritance »

 

Derived class inheriting from a base class.


 

import math

class Point:
   def __init__self, xValue = 0, yValue = ):
      self.x = xValue
      self.y = yValue

class CirclePoint ):
   def __init__self, x = 0, y = 0, radiusValue = 0.0 ):
      Point.__init__self, x, y )
      self.radius = floatradiusValue )

   def areaself ):
      return math.pi * self.radius ** 2

print "Point bases:", Point.__bases__
print "Circle bases:", Circle.__bases__


print "nCircle is a subclass of Point:", issubclassCircle, Point )
print "Point is a subclass of Circle:", issubclassPoint, Circle )

point = Point3050 
circle = Circle120892.7 )   

print "ncircle is a Point object:", isinstancecircle, Point )
print "point is a Circle object:", isinstancepoint, Circle )

print "npoint members:nt", point.__dict__
print "circle members:nt", circle.__dict__

print "nArea of circle:", circle.area()

   
  



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo Class
» Class Inheritance