Abstract class have both concrete and abstract function . interface only have abstract functions.
Overriding is possible in both. Is it
What is the real time advantage of one over the other ?
Abstract class have both concrete and abstract function . interface only have abstract functions.
Overriding is possible in both. Is it
What is the real time advantage of one over the other ?
Now, if class Animal is abstract class like
Here, abstraction works well, but if there are 100 objects like
Animal a[100]
;You can not write
new Bird().move
ornew Fish().move
100 timesUse interface and write
a[i].move
. It will differentiate as bird or fish and thatmove()
will be invokedSecond it supports multiple inheritance as class
A
can implements as many interfaces.Interfaces are useful because Java doesn't have multiple inheritance (but you can implement as many interfaces as you like).
Abstract classes are useful when you need concrete behaviour from the base class.
You dont override an interface. You implement it.
Writing an interface gives implementors the ability to implement your interface and also other interfaces in addition to inheriting from a base class.
Abstract classes can be partially or fully implemented.Marking a class abstract just prevents you from instantiating an object of that type.