M5 pt 2 Flashcards
declared either at the start or end
of a class definition. These variables identify
the data stored in the object.
Attributes –
a method that is automatically
executed when an object is created. This
method is used to initialize the attributes.
Constructor –
a method that is used
to change the data.
Mutator (Setter) –
a method that is
used to access or retrieve data.
Accessor (Getter) –
implement the business
rules for which the application is being
developed
Custom Methods –
Steps in Declaring Classes
- Define the class name
- Declare the attributes
- Create constructor
- Create standard methods
- Create custom methods
class declaration syntax
class { //code }
attributes declaration syntax
ex. private String name;
constructor declaration syntax
- {
- //code here
- }
Create standard methods (setters) syntax
- setXxx(args list)
- {
- //codes here
- }
Create standard methods (getters) syntax
- getXxx (args list)
- {
- //codes here
- }
Create custom methods syntax
- {
- //codes here
- }
contains a reference to the current object being
constructed. It represents an instance of the class in
which it appears. It can be used to access class variables
and methods.
this keyword
can be used to refer current class instance variable.
this()
can be used to invoke current class constructor.
this()
can be used to invoke current class method (implicitly)
this()
Variable: a variable that is only accessible within a class where it is declared. Method: a method that is only accessible within the class where it is declared.
private
Variable: a variable that is accessible from all classes. Method: a method that is accessible from all classes.
public
The default modifier is accessible only within the package. If you don't use any modifier, it is treated as default by default.
default (no keyword)
The protected access modifier is accessible within and outside the package but through inheritance only. It can be applied on the data member, method and constructor. It can't be applied on the class.
protected
modifiers/qualifiers
final, static, abstract, interface
variables stored in each object of a class,
usually referred to as the non-static member
fields of a class
Instance Variables (non-static fields) –
variables stored in the class and are available to all objects of a class or objects of other classes if access is permitted, usually referred to as the static members of the class.
Class Variables (static fields) –
data used in a method. This
data is temporary and does not exist once
the method has completed execution.
Local Variables (method variables or local data) –