Unit 3
Home-->Comp Sci
- Visibility modifiers
- defines who may call the method
- public the method is avaible to all clients
- private can only be called from within the defining class
- Object Identity
- the second it dosen't have a calling title is is deleted
- each has a unique identity, some may have similar charactistics or even appear to be the same, but are not the same, and should not be confused with the variables that might refer to the object
- Instance variables and methods
- a piece of data that is part of the object of the class
- almost always declared as private
- Constructor methods
- initialize the instance variables for a newly created object of the class
- must all have the same name of the class, and the compiler will distinguish based on the given parameters
- default
- copy
- chaining
- user defined
- Accessor Methods
- job is to print out specific parts of a method
- Modifer methods
- job is to change parts of the method
- toString method
public String toString()
- toString is a private version of the object
- automatically called when the println method is given
- Equals method
public boolean equals(object obj)
- allows the client programs to determine if two objects are "the same"
- method will return true if the objects are the same, false otherwise
- Parameters and return types
- the parameters listed in the method definition are called the "formal parameters"
- values passed to a method when called are arguments or "actural parameters"
- return types are void, double, boolean, int, and String, and if not void return must be written before it at the end of the method
- Scope of a variable
- largest block of code that a variable is known in
- local variable declared in a method can only be used in a method
- a "global" varable is declared independent of any sub-block of a program, thay are declared to be static
- the "lifetime" of a variable refers to the peroid during which it can be used