java ch6 Part3

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 8:22 PM on 4/8/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

18 Terms

1
New cards

Basic rules for the dice game Craps:

You roll two dice. Each die has six faces, which contain one, two, three, four, five and six spots, respectively. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first throw, you win. If the sum is 2, 3 or 12 on the first throw (called “craps”), you lose (i.e., the “house” wins). If the sum is 4, 5, 6, 8, 9 or 10 on the first throw, that sum becomes your “point.” To win, you must continue rolling the dice until you “make your point” (i.e., roll that same point value). You lose by rolling a 7 before making your point.

2
New cards

An enum type in its simplest form declares

a set of constants represented by identifiers. Special kind of class that is introduced by the keyword enum and a type name.

3
New cards

Braces delimit an enum declaration’s body. Inside the braces is

a comma-separated list of enum constants, each representing a unique value.

4
New cards

The identifiers in an enum must

be unique.

5
New cards

Variables of an enum type can be assigned

only the constants declared in the enum.

6
New cards

its good programming practices to use only uppercase letter in the name of

enum constants to make them stand out and remind you that they’re not variables.

7
New cards

its good programming practices to use enum constants (like Status.WON, Status.LOST, and Status.CONTINUE) rather than

literal values (such a 0, 1, and 2) makes programs easier to read and maintain.

8
New cards

Why Some Constants Are Not Defined as enum Constants:

Java does not allow an int to be compared to an enum constant. Java does not provide an easy way to convert an int value to a particular enum constant. Translating an int into an enum constant could be done with a separate switch statement. This would be cumbersome and would not improve the readability of the program (thus defeating the purpose of using an enum).

9
New cards

Scope of Declarations:

the portion of the program that can refer to the declared entity by its name, such an entity is said to be “in scope” for that portion of the program. Declarations introduce names that can be used to refer to such Java entities.

10
New cards

Basic scope rules:

The scope of a parameter declaration is the body of the method in which the declaration appears. The scope of a local-variable declaration is from the point at which the declaration appears to the end of that block. The scope of a local-variable declaration that appears in the initialization section of a for statement’s header is the body of the for statement and the other expressions in the header. A method or field’s scope is the entire body of the class.

11
New cards

Any Scope block may

contain variable declarations.

12
New cards

If a local variable or parameter in a method has the same name as a field of the class, the field

is hidden until the block terminates execution, this is called shadowing.

13
New cards

Method overloading:

Methods of the same name declared in the same class. Must have different sets of parameters.

14
New cards

With Method overloading the

Compiler selects the appropriate method to call by examining the number, types and order of the arguments in the call. Used to create several methods with the same name that perform the same or similar tasks, but on different types or different numbers of arguments. Literal integer values are treated as type int, so the method call in line 9 invokes the version of square that specifies an int parameter.

15
New cards

The compiler distinguishes overloaded methods by

their signatures, the methods’ name and the number, types and order of its parameters.

16
New cards

Return types of overloaded methods:

Method calls cannot be distinguished by return type.

17
New cards

Overloaded methods can have different

return types if the methods have different parameter lists.

18
New cards

Overloaded methods need not have

the same number of parameters.