[Java]--Abstract Class vs Interfaces

1. Abstract Class

Definition

  1. An abstract class is a class that is declared abstract—it may or may not include abstract methods.
  2. An abstract classes cannot be instantiated.
  3. An abstract classes can be subclassed.
  4. If a class include abstract methods, the class itself must be declared abstract.
    Some Code example:
public abstract class GraphicObject {
   // declare fields
   // declare nonabstract methods
   abstract void draw();
}

2. Abstract Methods

The subclass of the abstract class must implement all the abstract methods in its parent class. IF NOT, then the subclass must be declared abstract too

3. Interface

  1. Interface cannot be instantiated either.
  2. Interface may also contain a mix of methods declared with or without implementation .
  3. All fields are automatically public, static, and final.
  4. All methods that you declare or define (as default methods) are public.
  5. Methods in an interface (see the Interfaces section) that are not declared as default or static are implicitly abstract, so the abstract modifier is not used with interface methods. (It can be used, but it is unnecessary.)

Reference

  1. https://docs.oracle.com/javase/tutorial/java/IandI/abstract.html
  2. http://stackoverflow.com/questions/1320745/abstract-class-in-java
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值