Java Reference
In-Depth Information
< Day Day Up >
Puzzle 67: All Strung Out
One name can be used to refer to multiple classes in different packages. This program explores
what happens when you reuse a platform class name. What do you think it does? Although this is
the kind of program you'd normally be embarrassed to be seen with, go ahead and lock the doors,
close the shades, and give it a try:
public class StrungOut {
public static void main(String[] args) {
String s = new String("Hello world");
System.out.println(s);
}
}
class String {
private final java.lang.String s;
public String(java.lang.String s) {
this.s = s;
}
public java.lang.String toString() {
return s;
}
}
 
 
Search WWH ::




Custom Search