• Post Reply Bookmark Topic Watch Topic
  • New Topic

Usage of declaring abstract class even though all are concrete methods.  RSS feed

 
subash subbu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the usage of declaring a class as abstract class even though that contains all concrete(method with body)methods

Thanks in advance
Radha...
 
Ramon Anger
Ranch Hand
Posts: 56
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing that comes in my mind is that you can't instantiate an abstract class directly, so you have to inherit classes from it, that have their own type. You can overwrite the already implemented methods (if they are not final), but it's not necessary to do so.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An example is the MouseAdapter class. It implements the various mouse listener interfaces with empty method bodies, so you can use it as a base class for a mouse listener while only implementing the methods you need. But since it doesn't do anything until you've overridden it, it's completely pointless to instantiate it directly. So the designers decided they might as well prevent that, by making it abstract. It makes it clear it's intended to be used by subclassing it.
 
subash subbu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Advantage of placing concrete methods in abstract class is. The concrete sub class of that abstract class inherits those methods and overrides methods only if the subclass wants a specific behavior...
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also create an anonymous subclass of it.
For XXXAdapter, etc, you should always use the @Override annotation to make sure you have not misspelt the name of the method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!