Lecture 26, CS 302-7 and 8, March
21
i. Classes – compile time
ii. Objects – run time
iii. Example – blueprint/house
i. Public Interface
i. Accessors
ii. Mutators
i. Voting Machine
i. Method declarations - public interface
ii. Method bodies - private implementation
i. Declared for the entire class, not just for
one method
i. These are mentioned in the blue print
(declared), but they vary for different instances of houses built from that
blueprint (objects).
i. Need to consider the needs of each method in
determining how many/which ones to declare
i. We'll have an instance variable to keep track
of each of these.
i. Declared in the class, outside any methods.
ii. Usually at the top of the class.
iii. private
<type> <name>;
i. Since we declare these as private, they
cannot be accessed directly by the object.
Must use accessor instead.
i. Not static, usually public
ii. Located after instance variables in our
classes
i. Explicit parameter – declared in method
header
1. 0 or more of them
ii. Implicit parameter – the object itself
1. One and only one
i. Holds reference to the object itself (the
implicit parameter)
ii. Use to refer to instance variables from
within instance methods
1. this.<var>
i. For now, we won't consider the undoVotes
functionality
1. this.demVotes++;
return this.demVotes;