blob: fece1284047d82beb3dd0fe7a00dfca5a87f65e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package rtfl;
import java.util.LinkedList;
import java.util.List;
public class TestRtflObjects1
{
private static class A
{
private A other = null;
private List<Integer> numbers = new LinkedList<Integer>();
public void setOther (A other)
{
this.other = other;
}
public int doSomething (int n)
{
int r = (int)(Math.random() * 251);
numbers.add (new Integer (r));
if (other != null && n > 0)
other.doSomething (n - 1);
return r;
}
}
private static class B extends A
{
}
private static class C extends A
{
}
public static void main (String[] args)
{
A x = new A ();
B y = new B ();
C z = new C ();
x.setOther (y);
y.setOther (z);
z.setOther (x);
x.doSomething (8);
}
}
|