Java Reference
In-Depth Information
System.out.println(x);
}
public static void main(String[] args)
{
int n = 13;
print(n);
}
}
Exercise R8.25. Look at the methods in the
Integer
class. Which are
static? Why?
Exercise R8.26. Look at the methods in the
String
class (but ignore the
ones that take a parameter of type
char[]
). Which are static? Why?
Exercise R8.27. The
in
and
out
fields of the
System
class are public
static fields of the
System
class. Is that good design? If not, how could
you improve on it?
Exercise R8.28. In the following class, the variable
n
occurs in multiple
scopes. Which declarations of
n
are legal and which are illegal?
public class X
{
public int f()
{
int n = 1;
return n;
}
public int g(int k)
{
int a;
for (int n = 1; n <= k; n++)
a = a + n;
return a;
}
public int h(int n)
{
int b;
for (int n = 1; n <= 10; n++)
b = b + n;
return b + n;
}
379
380