CS51 - Spring 2010 - February 4
Extended discussion of problem 6.9.1 in the book
instance variables
keeps track of the state of an object
can be used in multiple methods
constructors
what does a new object "look" like?
at a minimum should initialize the instance variables.
parameters as a way of passing information
formal parameters in constructor/method declarations
scope is that constructor/method
actual parameters are passed in when that constructor/method is invoked.
what matters are that the types match (or can be converted, for example passing in an int when the method expects a double), and that the order is correct.
local variables
scope is only a single method (or constructor)
if something doesn't need to be an instance variable, don't make it one.
method overloading
two (or more) methods with same name, different signatures
convenient/good-style to have overloaded methods call each other if they do the same (or very similar) things
public vs. private
by default, instance variables should be private
methods can be public or private depending on what they're for
discussion of public vs. private constants
use of keyword
this
, both with methods and instance variables