I was taught that interfaces must have ALL abstract methods. But it looks from your post that if you have an abstract class in an interface, anything can be in that abstract class? (methods with bodies)?
Interfaces have all abstract methods implicitly except for those declared within nested classes.
Note that the given example is poor in that abstract classes with all concrete methods is generally poor. The class needn't be abstract for it to be a member of an interface. I use classes within interfaces to provide some implementation of the interface that is at the same level of abstraction as the interface - for example, a null implementation.
Hello Tony, could you provide some example or detailed explanation of nested classes within interface? I'm not sure how to use nested class in interface. Thanks
zmarak ahmad djan
Greenhorn
Joined: Sep 02, 2004
Posts: 20
posted
0
Originally posted by Tony Morris: The class needn't be abstract for it to be a member of an interface. .
absolutely right
the class in the example does not need to be abstract
but in this example there was a pedagogical intent in doing so I was trying to give some hints on why the class is here and why it should be here. designing a class that implements the interface gives some clues
David Ulicny
Ranch Hand
Joined: Aug 04, 2004
Posts: 724
posted
0
Hi Zmarak, can you show the usage of your interface and what role play the inner class there. Thanks
Something like
zmarak ahmad djan
Greenhorn
Joined: Sep 02, 2004
Posts: 20
posted
0
two different points here : -why the class in the interface ? - usage ?
point one : notice that the class and the interface definition depend on each other. if you declare this as two different compilation units it would be possible but would need to be compiled together the fact that the class is IN the interface expresses the fact that the definition of the interfaces need that class.
point two: - A) write a base class named "NormalProduct" and tax it. all derived class will derive from this class.
-B) now a 1.5 feature write a derived Interface IsTaxableSpecial extends IsTaxable where the method getTaxAgent returns a local subclass of TaxAgent write a class that derives from "NormalProduct" but implements IsTaxableSpecial. you're in for a (happy) surprise (courtesy J2SE 5)