Math107Ch5 - Introduction To Scientific Programming Chapter...

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

View Full Document Right Arrow Icon
Introduction To Scientific Programming Chapter 5 – More About Objects and Methods
Background image of page 1

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

View Full DocumentRight Arrow Icon
S.Horton/107/Ch. 5 Slide 2 Overview – More, More, More ! I. More on Methods A. Referencing B. Static Methods (and Variables) C. Overloading I. More on Classes A. Wrapper Classes B. Constructors C. Groups of Classes - Packages I. More on Software Design A. Top-Down Design B. Using Methods: Main/Helper/Class Interface
Background image of page 2
S.Horton/107/Ch. 5 Slide 3 I. More On Methods - Referencing What are the possibilities? Reference a method outside of its’ class Reference a method from inside its’ class Also must consider lifetime: Reference a method before a class object has been created Reference a method after a class object has been created
Background image of page 3

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

View Full DocumentRight Arrow Icon
S.Horton/107/Ch. 5 Slide 4 Public methods called outside and after an object definition has occurred simply require the object name to precede the method name. For example: //Define object myOracle Oracle myOracle = new Oracle(); ... //dialog is a method defined in Oracle class myOracle.dialog(); ... When an Object Name Is Required
Background image of page 4
S.Horton/107/Ch. 5 Slide 5 When An Object Name Is Not Required What if you want to use another method within the same class? You would need objectName , but it doesn’t exist yet. Answer: this. refers to the object that contains the current reference. Essentially, this. stands in for the object name. You may either use this. , or omit it, since it is presumed – i.e. methods called within an class definition file do not need to reference itself.
Background image of page 5

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

View Full DocumentRight Arrow Icon
S.Horton/107/Ch. 5 Slide 6 Class Method Reference Example public class AddressBook { private final int MAX_ENTRIES = 100; //Fixed size limit of 100 private String BookName; private int numberOfEntries; //--------------------------------------------------------------------------- // Method to find and display an entry in address book. //--------------------------------------------------------------------------- public boolean emptyBook() { if (this.numberOfEntries == 0) then //this. is optional return true; else return false; } //--------------------------------------------------------------------------- // Method that copies contents of AddressBook object //--------------------------------------------------------------------------- public void makeEqual(AddressBook otherObject) { otherObject.BookName = this.BookName; otherObject.numberOfEntries = this.numberOfEntries; otherObject.updateDate = this.updateDate; for (int i=1; i<this.numberOfEntries; i++) { If !(emptybook) then //this. not used, o.k.! } } }
Background image of page 6
S.Horton/107/Ch. 5 Slide 7 I.-B. Static Methods You’ve thought/seen that some methods don't need an object to do their job: Ex. a method to calculate the area of a circle of radius r You should just pass the required parameter and return the area! This is accomplished by using a static method. These
Background image of page 7

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

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

This note was uploaded on 09/08/2011 for the course MATH 107 taught by Professor Christinashow during the Spring '08 term at Mesa CC.

Page1 / 36

Math107Ch5 - Introduction To Scientific Programming Chapter...

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

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