Wednesday, August 4, 2010

Downcasting: Redwood.java

Courtesy of SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065) (9780071591065)
Chapter 2, Question 9














Code compiles, but JVM will throw a ClassCastException at runtime. JVM will not allow code to downcast; in this code, it is being done on

line 7: go2((Redwood)new Tree(), new Redwood();
line 10: Redwood r2 = (Redwood)t1;

No comments:

Post a Comment