[Java]--Abstract Class vs Interfaces
2016-08-20 13:24
387 查看
1. Abstract Class
Definition
An abstract class is a class that is declared abstract—it may or may not include abstract methods.An abstract classes cannot be instantiated.
An abstract classes can be subclassed.
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 too3. Interface
Interface cannot be instantiated either.Interface may also contain a mix of methods declared with or without implementation .
All fields are automatically
public, static, and
final.
All methods that you declare or define (as default methods) are public.
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
https://docs.oracle.com/javase/tutorial/java/IandI/abstract.htmlhttp://stackoverflow.com/questions/1320745/abstract-class-in-java
相关文章推荐
- Programming in Java: Multi-threads and interface vs abstract class
- interface VS abstract class in java
- Programming in Java: Multi-threads and interface vs abstract class
- Programming in Java: Multi-threads and interface vs abstract class
- [Java] Abstract classes vs. interfaces
- Programming in Java: Multi-threads and interface vs abstract class
- java abstract class vs interface
- Programming in Java: Multi-threads and interface vs abstract class
- java interface vs abstract class
- Java abstract class vs interface
- Programming in Java: Multi-threads and interface vs abstract class
- Abstract class VS Interface 转载
- abstract class VS interface[转]
- difference between Abstract class and interface in java
- difference between Abstract class and interface in java
- Is it an abstract class?; nested exception is java.lang.InstantiationE... (转帖)
- A rule of thumb about Interface vs Abstract Class
- difference between Interface and abstract class in Java
- Interfaces vs Abstract Classes...
- Java Abstract class and Interface