top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

when we go for interface and Abstract class in java

+1 vote
255 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 Google+ Share Button LinkedIn Share Button Multiple Social 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 ?
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...