Differentiate between an abstract class and an interface.

Technology CommunityCategory: OOPDifferentiate between an abstract class and an interface.
VietMX Staff asked 3 years ago

Abstract Class:

  1. A class can extend only one abstract class
  2. The members of abstract class can be private as well as protected.
  3. Abstract classes should have subclasses
  4. Any class can extend an abstract class.
  5. Methods in abstract class can be abstract as well as concrete.
  6. There can be a constructor for abstract class.
  7. The class extending the abstract class may or may not implement any of its method.
  8. An abstract class can implement methods.

Interface

  1. A class can implement several interfaces
  2. An interface can only have public members.
  3. Interfaces must have implementations by classes
  4. Only an interface can extend another interface.
  5. All methods in an interface should be abstract
  6. Interface does not have constructor.
  7. All methods of interface need to be implemented by a class implementing that interface.
  8. Interfaces cannot contain body of any of its method.