| 1 | // instance.java -- test the `instanceof' operator.
|
|---|
| 2 |
|
|---|
| 3 | import java.util.EventListener;
|
|---|
| 4 |
|
|---|
| 5 | public class instance implements EventListener
|
|---|
| 6 | {
|
|---|
| 7 | public static void main (String[] args)
|
|---|
| 8 | {
|
|---|
| 9 | Object x1 = new instance ();
|
|---|
| 10 | EventListener x2 = new instance ();
|
|---|
| 11 | IllegalArgumentException iae
|
|---|
| 12 | = new IllegalArgumentException ("any random class");
|
|---|
| 13 | String x3 = "zardoz";
|
|---|
| 14 | Object x4 = "zardoz";
|
|---|
| 15 |
|
|---|
| 16 | // Test simple object stuff
|
|---|
| 17 | System.out.println (x1 instanceof Object);
|
|---|
| 18 | System.out.println (x1 instanceof IllegalArgumentException);
|
|---|
| 19 | System.out.println (x1 instanceof EventListener);
|
|---|
| 20 | System.out.println (x1 instanceof String);
|
|---|
| 21 | System.out.println ("=");
|
|---|
| 22 |
|
|---|
| 23 | // Test with value which is an interface.
|
|---|
| 24 | System.out.println (x2 instanceof Object);
|
|---|
| 25 | System.out.println (x2 instanceof IllegalArgumentException);
|
|---|
| 26 | System.out.println (x2 instanceof EventListener);
|
|---|
| 27 | System.out.println ("=");
|
|---|
| 28 |
|
|---|
| 29 | // Test with value which is a final class.
|
|---|
| 30 | System.out.println (x3 instanceof Object);
|
|---|
| 31 | System.out.println (x3 instanceof String);
|
|---|
| 32 | System.out.println ("=");
|
|---|
| 33 |
|
|---|
| 34 | // Test with value which is a random class.
|
|---|
| 35 | System.out.println (iae instanceof Object);
|
|---|
| 36 | System.out.println (iae instanceof IllegalArgumentException);
|
|---|
| 37 | System.out.println (iae instanceof EventListener);
|
|---|
| 38 | System.out.println ("=");
|
|---|
| 39 |
|
|---|
| 40 | // Test with value which is a final class, but not known
|
|---|
| 41 | // statically.
|
|---|
| 42 | System.out.println (x4 instanceof Object);
|
|---|
| 43 | System.out.println (x4 instanceof IllegalArgumentException);
|
|---|
| 44 | System.out.println (x4 instanceof EventListener);
|
|---|
| 45 | System.out.println (x4 instanceof String);
|
|---|
| 46 | System.out.println (x4 instanceof int[]);
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|