In all my projects there were many interfaces being defined and used but never did I get chance to use an abstract class. An interviewer asked me where did you use interfaces I told him the scenerios as I had used them Then he asked me about abstract classes. I explained him but he also wanted to know where I used. I could not tell as I have never used an abstract class in my career.What are the practical scenerios in application where they use them
I've never created an abstract class, either, but for further information, read the topic "abstract class Vs Interface real life scenerios" linked in the "Similar Threads" box at the bottom of this page; it has some good information.
Another example is the javax.servlet.http.HttpServlet class. It has lots of useful methods for implementing servlets, but by itself does not do anything useful - so in order to make sure that it is being extended, instead of being used directly, it is declared abstract.
I use abstract classes all the time. First, I create an Interface that defines the needed methods. Then I decide which methods are going to be common to all subclasses/implementations. These methods go in the abstract class.
All concrete implementations (classes) simply declare that they extend the abstract class and implement the interface. They all get all the common code.
Joined: Jul 07, 2012
Abstract class would serve the purpose when you want to declare Custom Exception for your entire Application.
I will try this and try to understand why abstract class serves the purpose here.