Java Reference
In-Depth Information
d. By changing the start angle of the smile arc to 10, the starting point
is now on the right side of the snowman's face instead of the left. The
“direction” of the arc is still counterclockwise. Thus, the arc curves
downward instead of upward and the happy snowman is now sad.
e. The upper torso “disappears” since it merges with the background.
Chapter 3 Using Classes and Objects
3.1 Creating Objects
SR 3.1
A null reference is a reference that does not refer to any object. The
reserved word null can be used to check for null references before fol-
lowing them.
SR 3.2
The new operator creates a new instance (an object) of the specified
class. The constructor of the class is then invoked to help set up the
newly created object.
SR 3.3
The following declaration creates a String variable called author and
initializes it:
String author = new String ("Fred Brooks");
For strings, this declaration could have been abbreviated as follows:
String author = "Fred Brooks";
This object reference variable and its value can be depicted as follows:
author
"Fred Brooks"
SR 3.4
To set an integer variable size to the length of a String object called
name , you code:
size = name.length();
SR 3.5
Two references are aliases of each other if they refer to the same object.
Changing the state of the object through one reference changes it for the
other because there is actually only one object. An object is marked for
garbage collection only when there are no valid references to it.
3.2 The String Class
SR 3.6
Strings are immutable. The only way to change the value of a String
variable is to reassign it a new object. Therefore, the variables changed
by the statements are: a. none, b. s1 , c. none, d. s3 .
Search WWH ::




Custom Search