| |
GeekInterview.com > Interview Questions > J2EE > Java
| Print | |
Question: What is the difference between Abstract class and Interface
Answer: Answered by Scott on 2005-05-12 10:03:06: An abstract class can contain non-abstract methods which do not have to be overridden in the subclass. There is no difference between a fully abstract class (all methods declared as abstract and all fields are public static final) and an interface. |
| July 07, 2007 04:49:20 |
#14 |
| Akanksha Rakesh |
Member Since: Visitor Total Comments: N/A |
RE: What is the difference between Abstract class and ... |
In design, you want the base class to present only an interface for its derived classes. This means, you don’t want anyone to actually instantiate an object of the base class. You only want to upcast to it, so that its interface can be used. This is accomplished by making that class abstract using the abstract keyword. If anyone tries to make an object of an abstract class, the compiler prevents it. The interface keyword takes this concept of an abstract class a step further by preventing any method or function implementation at all. You can only declare a method or function but not provide the implementation. The class, which is implementing the interface, should provide the actual implementation. |
| |
Back To Question | |