Monday, August 2, 2010

Inner Classes: AbstractTest.java

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




















Output for this program is 57 22.

Line 11: t refers to an instance of an anonymous (unnamed) subclass of  AbstractTest. t has it's own getNum() method which overrides the getNum() for  AbstractTest. Similar case with the instance of AbstractTest.Baz.

Line 16: Now that an instance of the outer class AbstractTesthas been created, you can create instance of the inner class Baz{}. Please note, if you are outside the outer class and want to create an instance of an inner class, you must first invoke an instance of the outer class to tie the inner class to. Outside of AbstractTest,  Baz cannot be invoked independently.

No comments:

Post a Comment