Week 4 Flashcards
an object created from a class has …
a state and behaviors
all classes that represent objects should …
declare a toString method
a constructor is called by …
the new operator to create an object and set its initial state. It looks similar to a method but has the same name as the class and has no return type.
a constructor may or may not have parameters. A class may have multiple constructors.
a constructor may or may not have parameters. A class may have multiple constructors.
the scope of a variable defines …
where it can be referenced; determined where the variable is declared (its enclosing block)
instance variables
(fields declared in the class black) can be referenced by all methods in that class.
local variables
variables (declared inside of a method) can only be referenced within that method.
UML
Unified Modeling Language - shows the relationship among classes in the program
-three kinds of access modifiers:
public(anywhere), protected, and private(within the class) -no access modifiers access is default and can be referenced within the class and by classes in the same package
Access (Visibility) Modifiers
Public Private
Instance Variables Violate encapsulation Enforce encapsulation
Methods Provides services to clients Support other methods in the class
An accessor method returns …
the current value of a variable (getter) getX()
A mutator method changes …
the value of a variable (setter) setX()
The return type of a method indicates…
the type of value that the method sends back to the calling location.
magic numbers
do not use magic numbers in constant fields
unlike variables, constants can be …
public without violating encapsulation