Final Gaddis Chap 3 part 2 Flashcards
UML diagrams are
language independent
UML diagrams use
an independent notation to show return types, access modifiers, etc
variable types are placed
after the variable name, separated by a colon
ex:
-width: double
Access modifiers are denoted as
+ for public
- for private
# for protected
method return types are placed
after the method declaration name, separated by a colon
method parameters are placed
inside parenthesis after the setMethod
UML order from top to bottom
ClassName, Attributes (Variables to be initiated), Methods (Constructor, getters, setters, calculations)
Can methods have multiple parameters?
Yes.
Parameters in methods are treated as
local variables within the method
In Java, all arguments to a method are passed…
“by value”
if the argument is a reference to an object
it is the reference that is passed to the method
if the argument is a primitive,
a copy of the value is passed to the method
instance fields and methods
fields and methods that are declared as previously shown
objects created from a class each have their own copy of
instance fields
instance methods are methods that are not declared with a special keyword…
static
instance fields and instance methods require
an object to be created in order to be used
constructors have a few special properties that set them apart from normal methods
1) have same name as the class
2) have to return type (not even void)
3) they cannot return any values
4) are public
write a constructor for the Payroll class with argument String n and int i
public Payroll (String n, int i) { name=n; idNumber=i; }
In a UML chart, you can tell what the constructor is because
it will not have a return type and it will share a name with the class
Scope of a variable inside of a method
visible only within that method, called a local variable
scope of a variable inside a method parameter
called a parameter variable (same as local variable) and visible only within that method
Scope of a variable inside the class but not in a method
visible to all methods of the class, called an instance field
within a method, variable names must be
unique
shadowing
a method having a local variable with the same name as an instance field (hides value of instance field) this is discouraged