Lecture 27, CS 302-7 and 8, March
23
i. Declare as private
ii. Initialized to ‘zero’ value
1. objects null, ints zero, etc
iii. Remember variable scope
i. Accessors
1. ‘getters’
2. Boolean methods
ii. Mutators
1. ‘setters’
iii. Methods can do both as well – this is just a
semantic distinction, not a rule
iv. Implicit variable
1. this
v. Explicit variables
i. Each one must have unique args (by type and
number and order)
1. different name but everything else the same
does not count
ii. When we new an object, the variables must
match the args for one of the constructors.
i. Import
1. find it
2. Note – since we are in the same directory,
don’t need to do this with our classes.
Example, though, is java.util.Scanner;
ii. Declare
1. <Class> <varName>;
iii. Construct
1. make it
2. <varName>=new <Class>(< params
>);
iv. Use
1. use it
<varName>.<method>(<params>);
2. by calling methods from the object
3. Joke - “An OO surgeon would hand the scalpel
to the patient and say: "now perform this operation on yourself!".”
i. Testing parts of a program in isolation,
outside the full program.
1. aka making sure each class works as desired.
i. Only need to when there is potential
scope conflict.