Java Reference
In-Depth Information
< Day Day Up >
Puzzle 50: Not Your Type
This puzzle tests your understanding of Java's two classiest operators:
instanceof
and cast. What
does each of the following three programs do?
public class Type1 {
public static void main(String[] args) {
String s = null;
System.out.println(s instanceof String);
}
}
public class Type2 {
public static void main(String[] args) {
System.out.println(new Type2() instanceof String);
}
}
public class Type3 {
public static void main(String args[]) {
Type3 t3 = (Type3) new Object();
}
}
Solution 50: Not Your Type
Search WWH ::
Custom Search