Java抽象類別和介面

Java抽象類別與介面以及它們的差異。

Abstract class

  • Can have both abstract and concrete methods;
  • A class can extend only one abstract class;
  • Can have protected, public and public abstract methods;
  • Can have static, final, or static final variables with any access modifier;
  • "is-a" relationship;
  • Cannot be instantiated;

Interface

  • Can have only abstract methods;
  • A class can implement multiple interfaces;
  • Can have only public abstract methods;
  • Can have only static final (constant) variables;
  • "like-a" relationship;
  • Can extend another interface;

參考文獻

java