Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

WithoutBook Forum

Ques. What is difference between abstract and interface in java?

- What is difference between abstract and interface in java?

Posted on Sep 26, 2010 by Raj PR
Ans. Abstract classes are used only when there is a "IS-A" type of relationship between the classes.
Interfaces can be implemented by classes that are not related to one another and there is "HAS-A" relationship.

You cannot extend more than one abstract class.
You can implement more than one interface.

Abstract class can implemented some methods also.
Interfaces can not implement methods.

With abstract classes, you are grabbing away each class’s individuality.
With Interfaces, you are merely extending each class’s functionality.
Posted on Sep 26, 2010 by Arindam Ghosh

Ans. 1. Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. An abstract class can contain no abstract methods also i.e. abstract class may contain concrete methods. A Java Interface can contain only method declarations and public static final constants and doesn't contain their implementation. The classes which implement the Interface must provide the method definition for all the methods present.

2. Abstract class definition begins with the keyword "abstract" keyword followed by Class definition. An Interface definition begins with the keyword "interface".

3. Abstract classes are useful in a situation when some general methods should be implemented and specialization behavior should be implemented by subclasses. Interfaces are useful in a situation when all its properties need to be implemented by subclasses

4. All variables in an Interface are by default - public static final while a
Posted on Sep 28, 2010 by Raj PR

Enter your Answer

Name
Email Address
Answer
©2024 WithoutBook