The following code:
Animal a = new Dog(); Dog d = (Dog)a; d.doDogStuff();
Can be replaced with this easy-to-read bit of fun:
Animal a = new Dog(); ((Dog)a).doDogStuff();
In this case the compiler needs all of those parentheses, otherwise it thinks it's been handed an incomplete statement.
Refrence: SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065)
No comments:
Post a Comment