Difference Between Abstract Class and Interface Class

Abstract classes are created to provide partial class implementation of an interface. We can complete an implementation using the derived classes. Abstract classes contain abstract methods, which can be implemented by using abstract classes and virtual functions.

There are certain rules governing the use of the abstract class. These are:

  • Cannot create an instance of an abstract class
  • Cannot declare an abstract method outside an abstract class
  • Cannot be declared sealed (Sealed classes can never be inherited)

The syntax to declare a class Abstract is:

abstract class classname
{
..........
}

Interface is a collection of abstract methods. An interface is not a class. Writing an interface and writing a class are similar, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors that a class implements.

For e.g.

interface Animal

{

public void eat();

public void run();

}

public class Dog implements Animal

{

   public void eat()

{

   System.out.println("Dog eats");

}

public void run()

{

   System.out.println("Dog runs");

}

public int noOfLimbs()

{

  return 0;

}

public static void main(String args[])

{

   Dog d = new Dog();

   d.eat();

   d.run();

}

The output would be:

Dog eats
Dog runs

Next Recommended Reading Abstract Class And Interface