Study sets, textbooks, questions
Upgrade to remove ads
Understanding Class Definitions
Terms in this set (30)
What does the class comment do?
it gives information about the class: says what the class does, name of authors & version number
How should you write class sames?
The name of a class starts with a capital letter & each word starts with a capital letter
What are reserved words?
They have special meaning e.g. public, private, int. Always lower case
What are fields like?
stores values for an object
define the state of an object (use inspect to view state)
aka instance variables
some values change often, some change rarely
e.g. private int price;
private: visibility modifier (fields are always private)
price: variable name (Should be lower case)
How should you write fields?
always private, variable name should be lower case
What are constructors like?
Initialises an object into a valid starting state
must be public- so they can be called by someone who wants to use the class
name is the same as their class
may have parameters
special kind of method
has a body- with statements (what happens)
close association with fields- initial values stored into the fields & parameter values used
What are parameters in the constructor like?
are temporary variables that only exist while the constructor is executing
What are methods like?
Implement the behaviour of objects
have a header & a body
2 types: accessor, mutator
What do accessor methods do?
provide information about an object
What do mutator method do?
alter the state of an object
What do headers tell you?
visibility to object of other classes (public so can be called by other objects)
whether the method returns a result
name of the method
whether the method takes parameters
What are accessor methods like?
always has a return type that is not void
returns a value (result) of the type given in the header
contains a return statement
return is not printing
does not change the state of an object
What are mutator methods like?
has a header & body
mutates an object's state e.g. changes value in balance field
changes the value of one or more fields (contains one or more assignment statements, often receives parameters)
typically does not return a value (void)
What does System.out do?
references object that represents the BlueJ output terminal
What does println do?
it is a method that writes something to the terminal
Sets found in the same folder
Building GUIs, Part 1
Classes & objects
9 Working in Teams
Other sets by this creator
9 Making the most of models
8 Agile Software Development
10 Sorting Algorithms
9 Search Tree Structures