RU beehive logo ITEC dept promo banner
ITEC 120
2012fall
dbraffitt
ibarland

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs

lect08c
loop intro

Reminder: “static” means associated with                 , not with any particular                 .

The purpose of a constructor is to:                 

For fields: If you have created 100 Song objects, then you have                  fields for title, and                  fields for MB_PER_SEC. Even if you have zero Song objects created, you still have                  static field.

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 toString method. Then you came along later, made class Robot, and made your own tailored toString for it -- and my old legacy code calls your recent toString automatically!

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.

let's play: static, or not?

Answers: lect08c-soln.html
Our starting code
 - 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 statement

Our starting code

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs


©2012, Ian Barland, Radford University
Last modified 2012.Nov.04 (Sun)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme