Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   difference between an Interface and an Abstract class (http://www.go4expert.com/forums/difference-interface-abstract-class-t18109/)

web development 19Jun2009 17:17

difference between an Interface and an Abstract class
 
What is the difference between an Interface and an Abstract class?

shabbir 19Jun2009 18:02

Re: difference between an Interface and an Abstract class
 
Here are some of them
  1. Abstract classes can have implementations for some of its members (Methods), but the interfaces can't have implementation for any of its members.
  2. An interface can extend another interface, but cannot extend an abstract class.
  3. All variable in interfaces are final by default
  4. Interfaces provide a form of multiple inheritance. A class can extend only one other class at least in Java and C#
  5. In Abstract Class atleast one of its method needs to be defined in subclass where as in interface all methods needs to be defined in subclass.
  6. Accessibility like Public/Private/protected are only allowed in abstract class and not in Interface

gkumar 22Jun2009 15:13

Re: difference between an Interface and an Abstract class
 
1) Abstract class defines few or none of the methods, but
interface defines all the methods..
2) Abstract classes should have subclasses else that will
be useless..
Interfaces must have implementations by other classes else
that will be useless
3)only an interface can extend another interface, but any
class can extend an abstract class..
4)All variable in interfaces are final by default


All times are GMT +5.5. The time now is 01:40.