lec21_classes2

Lec21_classes2 - Super and sub classes Create a superclass which is has methods common to a range of subclasses class Shapes def calcVolume(self,h

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
##### Super and sub classes ####### # Create a superclass which is has methods common to a range of subclasses class Shapes(): def calcVolume(self,h): area = self.calcArea() #The next line allows the 'h' value to be access by the subclasses self.h=h return area*self.h # Define some specific subclasses which inherit # the methods from the Shapes superclass class Square(Shapes): def __init__(self,s=1.0): self.s = s def calcArea(self): self.area = self.s**2 return self.area def calcPerim(self): return 4.0*self.s class Circle(Shapes): def __init__(self,r=1.0): from math import pi self.pi = pi self.r = r def calcArea(self): self.area = self.pi*self.r**2 return self.area def calcPerim(self): return 2.0*self.pi*self.r #################### #Function Class for height (y) of a ball thrown in the air ################### class Ball: """ Ball class for a ball trown in the air. Arguments: y0: initial height v0: initial velocity Methods: height(t): returns height at time t (t is float or array) initParams(): returns tuple of initial parameters for a ball
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/05/2010 for the course PHYS phy503 taught by Professor Gladden during the Spring '09 term at Ole Miss.

Page1 / 3

Lec21_classes2 - Super and sub classes Create a superclass which is has methods common to a range of subclasses class Shapes def calcVolume(self,h

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online