This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
If the inner class is an abstract one ,is it required that outer class shoud be declared as an abstract class. cos the non-static inner class is some thing like a class instance variable or method right?? ( ofcourse i got the answer that it need be!! am looking for any explanation !! thanks in advance)
Joined: Jan 30, 2000
See my example above. I never post code like that without compiling it first. So if an inner class is abstract, the outer class doesn't have to be.
Joined: Nov 22, 2008
Oh Sorry there is typo there that's what i mean it " need not be".My question is why is it so ? . Normally if any one method of a class is abstract then class must be defined as abstract isn't it?
Yes - but that's just the relationship between methods and the class that contains them. There is no such rule for inner classes and the class that contains them. The reason that abstract methods force the entire class to be abstract is to prevent the possibility that a class could be instantiated without an implementation of one of its methods. In the case of abstract inner classes, it is already impossible to instantiate the inner class (as soon as you call a constructor for it, you get "can't instantiate abstract class"). So there is no way to write any code that would successfully access any abstract (undefined) features, and additional "protection" (in the form of an additional rule) is unnecessary.