Java Reference
In-Depth Information
figure 3.18
Code for
Exercise 3.13
1
class Person
2
{
3
public static final int NO_SSN = -1;
4
5
private int SSN = 0;
6
String name = null;
7
}
8
9
class TestPerson
10
{
11
private Person p = new Person( );
12
13
public static void main( String [ ] args )
14
{
15
Person q = new Person( );
16
17
System.out.println( p ); // illegal
18
System.out.println( q ); // legal
19
20
System.out.println( q.NO_SSN ); // ?
21
System.out.println( q.SSN ); // ?
22
System.out.println( q.name ); // ?
23
System.out.println( Person.NO_SSN ); // ?
24
System.out.println( Person.SSN ); // ?
25
}
26
}
Is the following import directive, which attempts to import virtually
the entire Java library, legal?
3.16
import java.*.*;
Suppose the code in Figures 3.3 (
TestIntCell
) and 3.4 (
IntCell
) are
both compiled. Then, the
IntCell
class in Figure 3.4 is modified by
adding a one-parameter constructor (thus removing the default zero-
parameter constructor). Of course if
TestIntCell
is recompiled, there
will be a compilation error. But if
TestIntCell
is not recompiled, and
IntCell
is recompiled by itself, there is no error. What happens when
TestIntCell
is then run?
3.17
IN PRACTICE
3.18
A
combination lock
has the following basic properties: the combina-
tion (a sequence of three numbers) is hidden; the lock can be opened
by providing the combination; and the combination can be changed,
but only by someone who knows the current combination. Design a
Search WWH ::
Custom Search