top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

when we go for interface and Abstract class in java

+1 vote
816 views
when we go for interface and Abstract class in java
posted Oct 3, 2013 by Nagarajuk

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes

If u want multiple inheritance in java then u will use interface.
Interface is pure abstract class if u implements interface then it is necessary to override all methods of interface otherwise ur class become abstract class.

If u don't want multiple inheritance u will use Abstract class.

If u extends abstract class then overriding only necessary for abstract methods.

answer Oct 3, 2013 by Dheerendra Dwivedi
Any real life example ?
+1 vote

Always use an interface unless you need to ...

... provide subclasses with some state
... provide subclasses with default implementations of some methods
... want to defer implementation of some of the abstract methods

Note that you can only extend one class, while you can implement multiple interfaces. So if there's any chance that a subclass will need to extend some other class, strive for using an interface.

answer Oct 3, 2013 by Deepak Dasgupta
Any real life example ?
...