Chap5- revisited (Classes) Flashcards Preview

Java 1 > Chap5- revisited (Classes) > Flashcards

Flashcards in Chap5- revisited (Classes) Deck (24)
Loading flashcards...
1

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.

2

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.

3

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.

4

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.

5

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

6

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.

7

give an example of concatenation with an object:
account1
vairable: addInterest
()
result of the account with interest: total

total = account1.addInterest()

8

where are variables initialized or declared?

within the main method, before any method or within a method.
usually before any method first.

9

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.

10

how are custom methods made? what is the format?

public int methodName (parameters if desired)
{ body of the method }
Return;

11

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

Void

12

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..

13

what is the format of a mutator?

mutator:
public void setFaceValue (int value accepted can be variable name)
{ faceValue = value; }

14

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.

15

format of an acessor?

public int getFaceValue ( )
{ return faceValue: }
faceValue here is a private object.

16

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");
}

17

what is += operator, how does it work?

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

18

UML diagram?

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

19

data members are what?

instance variables also called fields.

20

instantiation?

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

21

what is a method?

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

22

what are the access modifiers?

public static
private

23

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

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

24

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.