-1

If interface has 2 method A() And B() and abstract class has also same A() and B() then what is the different between them?

k-s
  • 2,192
  • 11
  • 39
  • 73
  • Does no one of the provided answers satisfy you? – Manuel Rauber Mar 06 '13 at 17:57
  • yes, because both interface and abstract does method abstraction at one level. – k-s Mar 07 '13 at 05:58
  • possible duplicate of [When to use an interface instead of an abstract class and vice versa?](http://stackoverflow.com/questions/479142/when-to-use-an-interface-instead-of-an-abstract-class-and-vice-versa) – nawfal Jul 07 '14 at 10:15

3 Answers3

0

An interface just provides a skeleton of a class which implements this interface.

A abstract class (which can implement an interface, too) can add some default functionality which (of course) can be overridden in derivated classes.

Take a look at: Interface vs Abstract Class (general OO)

Community
  • 1
  • 1
Manuel Rauber
  • 1,583
  • 1
  • 17
  • 39
0

The difference is that classes that implement the interface will be forced to provide their own implementation of these methods, while classes that extend the abstract class will be provided with an implementation of these methods.

Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
0

Differences:

Assuming A() and B() don't have implementation in abstract class, i.e. only signatures.

  1. In case of the interface A() and B() will only be signatures, i.e. without any implementation and class implementing this interface will have to provide the implementation like this (without keyword override):

    returnType AbstractClass.A()
    {
        // Code here
    }
    
  2. A class implementing Abstract class will have to override the abstract methods like this:

    override accessSpecifier returnType A()
    {
        // Code here
    }
    
    override accessSpecifier returnType B()
    {
        // Code here
    }
    
Jamal
  • 763
  • 7
  • 22
  • 32
tariq
  • 2,193
  • 15
  • 26