Chap5- revisited (Classes) Flashcards Preview

Java 1 > Chap5- revisited (Classes) > Flashcards

Flashcards in Chap5- revisited (Classes) Deck (24)
Loading 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:
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 }


what word is used in a method header if no value is returned?



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?

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.


what does the toString method do and give example of format:

toString is used to return a string representation of an object.
public String toString () {
return (variableName + otherObjectName + "thanks");


what is += operator, how does it work?

sample += MAX * LEAST
same as:
sample = sample + ( MAX * LEAST)


UML diagram?

Unified Modeling Diagram
used to outline a visual representation of a class


data members are what?

instance variables also called fields.



creating a new object within a class.
instantiated object inherit values from the class it is in.


what is a method?

created within a class. collection of statements that make up an operation. or set of instructions that make an operation.


what are the access modifiers?

public static


what is the purpose of using methods before the main()?

it breaks down the code problem into easier to read chunks.


when we write a program and decide to break it down into readable chunks then how do we do this and what is the format?

We break it down into methods so it is easier to read. The methods use: public static --with void if nothing is returned. the portion of code that uses the methods is called the -- main method and calls on the method names.