lec21_classes2

lec21_classes2 - Review of Classes and methods Super and...

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

View Full Document Right Arrow Icon
University of Mississippi Dept. of Physics and Astronomy Phys 503, Dr. Gladden Review of Classes and methods Super and sub classes Function Classes Polymorphism HW08 due today. Reading on Classes and Object Oriented Programming is in Chap. 7 and 9 of your book.
Background image of page 1

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

View Full DocumentRight Arrow Icon
University of Mississippi Dept. of Physics and Astronomy Phys 503, Dr. Gladden Classes are defined like functions. The associated methods ARE functions within the class Once a Class is defined, an instance needs to be created (S1 and S2 in example) Then methods can be called on each instance of the object i.e. S1.draw() returns the area of S1. Real code example: Charge Class class Shape: def geometry(): #some code def draw(): #code to draw it def area(): #code to compute area #how to use it S1=Shape() S2=Shape() S1.area() #returns area of S1 S2.draw() #draw S2 to screen
Background image of page 2
University of Mississippi Dept. of Physics and Astronomy Phys 503, Dr. Gladden One sort of strange thing is the ‘self’ parameter. This is needed because many instances of a class can be defined. The self refers to a particular instance of the class. In charge class: q1=Charge() and q2=Charge() creates two different ‘self’s. So, when you call a method, it is applied to the right object:
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
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 / 11

lec21_classes2 - Review of Classes and methods Super and...

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

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