Chap5- revisited (Classes) Flashcards

1
Q

what is a visibility modifier and what are some examples?

A
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is the structure of a constructor?

A
same name as the class
constructor can have parameters that would be filled in when the constructor is called on.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how do we keep private variables private but are able to update them?

A

private variables can be updated with values if we use a public object and assign it to a private initialization/ object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

give an example of a private object being updated.

private client;

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a user created class vs a regular class?

A
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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

how does concatenation work with a variable and an object?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A

total = account1.addInterest()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

where are variables initialized or declared?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how is a constructor made?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

how are custom methods made? what is the format?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

Void

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is a mutator and are there other names for it?

A
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..
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is the format of a mutator?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what is an accessor? another name for it?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

format of an acessor?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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

A

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

17
Q

what is += operator, how does it work?

A

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

18
Q

UML diagram?

A

Unified Modeling Diagram

used to outline a visual representation of a class

19
Q

data members are what?

A

instance variables also called fields.

20
Q

instantiation?

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

what is a method?

A

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

22
Q

what are the access modifiers?

A

public static

private

23
Q

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

A

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

24
Q

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?

A

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.