RU beehive logo ITEC dept promo banner
ITEC 120
2010fall
ibarland

homeinfolectslabsexamshws
tutor/PIsObject120 + its docsjava.lang docsjava.util docs

lect06b
Objects: fields
Songs, Robots cont.

We continue our exploration of objects from the previous lecture (and lab).

Review: Where do you put fields, in the class-file?;
what is different about a constructor -- what name to use when calling constructor?;
when writing the signature, three differences from normal signatures?

To access an object's fields

We access fields using the . (“dot”) operator.

For example: If we have a variable s of type Song, then we can refer to s.length, s.title, etc..

The general syntax is:

field-access ::= exprobject.namefield
(The subscripts are just a reminder -- the technical syntax would be expr.name.)

We'll see later, how the exprobject doesn't need to be just a variable (or parameter), though often it is.

Functions taking in objects

Functions returning objects

(See the links above.)


1 Hopefully we get the question, after making test cases: What to do in case of a tie? Note that Java forces us to return a Song, and exactly one Song, by our signature. In light of that, we'll say longerOf can return either one in case of a tie.      

homeinfolectslabsexamshws
tutor/PIsObject120 + its docsjava.lang docsjava.util docs


©2010, Ian Barland, Radford University
Last modified 2010.Oct.07 (Thu)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme