public abstract class Animal {} public class Bear extends Animal {} public class Test { public Animal go () { return new Bear(); // OK, Bear "is-a" Animal } }
This code will compile, the return value is a subtype.
Refrence: SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065)
No comments:
Post a Comment