Chap5- revisited (Classes) Flashcards
what is a visibility modifier and what are some examples?
visibility modifier: modifier that defines the scope in which a construct can be accessed. public methodName() means any class can access private int variableName; means it is encapsulated and can not be accessed by classes outside of the class.
what is the structure of a constructor?
same name as the class constructor can have parameters that would be filled in when the constructor is called on.
how do we keep private variables private but are able to update them?
private variables can be updated with values if we use a public object and assign it to a private initialization/ object.
give an example of a private object being updated.
private client;
client = customerName;
then use customerName as part of the parameter in the constructor so that when a driver tried to create an object and calls on the constructor then the private object gets updated with the same value.
what is a user created class vs a regular class?
user created class: a class that is created within its own program called a class.. created by me as a programmer so that it can be used by many diff. drivers/ programs. class: a class already created and comes in java library
how does concatenation work with a variable and an object?
object.variable( );
the object is an initialized name that represents something like a value.
-the variable is an action that takes place on the object.
the period . is the concatination
-the ( ) allows parameters or values to be invoked.
give an example of concatenation with an object:
account1
vairable: addInterest
()
result of the account with interest: total
total = account1.addInterest()
where are variables initialized or declared?
within the main method, before any method or within a method.
usually before any method first.
how is a constructor made?
constructor is the same name as the class itself.
- no return value because it just allows a program to create an object with certain parameters.
- the code is written in the class so that a driver can set up its objects.
how are custom methods made? what is the format?
public int methodName (parameters if desired)
{ body of the method }
Return;
what word is used in a method header if no value is returned?
Void
what is a mutator and are there other names for it?
mutator is the same as a setter. allows a driver to change the value of a private variable within the class that is otherwise unreachable..
what is the format of a mutator?
mutator:
public void setFaceValue (int value accepted can be variable name)
{ faceValue = value; }
what is an accessor? another name for it?
acesser also called a getter.
allows a driver to read the value of a private object name that is within the class.
-can only read, not alter the data.
format of an acessor?
public int getFaceValue ( )
{ return faceValue: }
faceValue here is a private object.