This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
My understanding of the purpose of abstract classes is that the abstract classes let you define some behaviors; they force your subclasses to provide others.
Now, an abstract class need not have any abstract methods. So if we do have an abstract class without any abstract methods then we will not be forcing a subclass to override any method.
So why would we want to have an abstract class without any abstract methods ? I noticed this as I was doing some reading on HttpServlet class. The HttpServlet class is an abstract class without any of its methods being abstract.
It�s possible to declare a class as abstract without including any abstract methods. This is useful when you�ve got a class in which it doesn�t make sense to have any abstract methods, and yet you want to prevent any instances of that class.
If the class were not abstract, then a developer may be tempted to use it as is. But in the case of HttpServlet, at least one of its methods must be overridden (usually doGet() or doPost()). So, my guess is that Sun is forcing a developer to subclass HttpServlet who, in doing so, is then more likely to do the right thing and override the appropriate method(s).
There are some abstract DefaultWhatever classes in Swing. They implement all the methods required by the Whatever interface, but all the methods do nothing. You can extend this class to override any methods you need with less effort than implementing all the methods in the interface. It feels like cheating somehow, but it's very handy.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
A bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Initials aren't enough. You can change your display name here. Thanks!