Java Reference
In-Depth Information
for (int i = 0; i < 5; i++) {
jagged[i] = new int[i + 1];
for (int j = 0; j < i + 1; j++) {
jagged[i][j] = value;
value++;
}
}
Chapter 8
1.
Procedural programming treats a program as a sequence of actions or commands
that must be performed. Object-oriented programming regards a program as a
group of interacting entities named objects that each keep track of related data
and behavior.
2. An object is an entity that encapsulates data and behavior that operates on the data.
A class is the blueprint for a type of object, specifying what data and behavior the
object will have and how to construct it.
3. The state of a String object is its sequence of characters (which are actually
stored internally as an array of char values). A String object's behavior includes
its methods, such as length , substring , toUpperCase , and indexOf .
4. 14 14
7 9 14 2
18 18
7 9 14 18
5. The state of a Calculator object might include the number that has just been
computed, as well as another number that is currently being input. A more com-
plex Calculator object might also include a memory feature that stores an addi-
tional value. The behavior of a Calculator object might include methods to add,
subtract, multiply, divide, and perhaps carry out other math operations (such as
exponentiation, logarithms, and trigonometric functions like sine and cosine).
6. A field is a variable that exists inside an object. A parameter is a variable inside a
method that has a value passed in from outside. Fields have different syntax
because they are usually declared with the private keyword and not in a
method's header. A field's scope holds throughout the class, while a parameter's
scope is limited to the method.
7. // A Name object represents a name such as "John Q. Public".
public class Name {
String firstName;
 
Search WWH ::




Custom Search