|
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
Reminder: “static” means associated with , not with any particular .
The purpose of a constructor is to:
For fields:
If you have created 100
For methods: If you haven't created any objects yet, you can't call any methods, but you can call a method.
Note the perspective-change: Rather than "hey function, give me the answer (and here are the arguments you need)", the object-oriented perspective thinks of it as "hey object, I want you do to something for me (and here is the *additional* info you need that you don't already have inside you)".
We have two ways of doing things, and have spent the week translating between static and object-oriented ways of doing the same thing.
Why? What does O.O. give us?
We'll see later: O.O. makes it easier to write future-compatiable code.
E.g. I wrote code a while back that took in an object and called its
tip: If the result of the function doesn't depend on which object you ask, it should be static -- don't ask an object.
equivalent tip: Also: "If it makes sense to ask the question even before a single object has ever been created, then it should be static" Otherwise, probably non-static.
- StudentTester: paste code several times repeat code - pull into helper function; note scope issues. - add an 'if' statement, to only continue while num hours is < 120. Note: the one-armed if. We have this when we have mutation (side-effects), (footnote: including modifying a local variable). - make a while statementOur starting code
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
©2012, Ian Barland, Radford University Last modified 2012.Nov.04 (Sun) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |