What are interfaces, abstract classes. What is their purpose and differences ?

Showing Answers 1 - 6 of 6 Answers

Vijaya Bhaskar M

  • Jul 24th, 2005
 

By default all methods present in the interfaces are abstract. where as we can provide method definition in the abstract class but we cont provide body to a method in the interface.?
Interfaces provides multiple inheritance in java. ?
abstract classes provides the facility to extend the functionality of a class.

  Was this answer useful?  Yes

Binod

  • Aug 25th, 2005
 

Interfaces:?

We can define only methods, no implementation.?
All methods are abstract.?
We can define variables, but those should be constants.?
?
Abstract classes?

Class which contains one or more abstract methods or class which is marked as abstract.?
We can have implementation inside this class.?
This class in meant to be extended by some other class, subclasses will provide implementation for abstract methods.?
?
Interfaces are a way of implementing multiple inheritance in java.?
?
Choice of usage depends on design decision.

Abstract Class:

Instance cannot be created.
Optionally can have one or more abstract methods but not necessary.
Can provide body to Classes.



Interface:


What a Class must do, But not how-to.

Bridge for the communication when the caller does not know to whom he is calling.

Describes externally visible behavior of element.

Only Public members which defines the means of the communication with the outer world. Can-be-Used-As Relationship.

Cannot contain data but can declare property.
There can be no implementation.
Interface can be derived from another interface




Difference between Abstract class and interface


In an interface class, all methods are abstract - there is no implementation.
In an abstract class some methods can be concrete.
In an interface class, no accessibility modifiers are allowed.
An abstract class may have accessibility modifiers

  Was this answer useful?  Yes

Interface (behavior) is same as class they have numerous of variable and methods.All methods which have interface is abstract methods.

Abstract class is class this is partial implementation gap for sub class implementation.Abstract class may have abstract methods and concrete methods.

When radical change of behavior without changing object is adopted then
interface is used.

When default behavior adopted in your system, at that time abstract class is very useful.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions