Abstract class:
What is an abstract class?
In object-oriented concepts, we know that all objects are depicted through classes , but not in the opposite way. Not all classes are used to depict objects, and if a class does not contain enough information to depict a specific object , such a class is an abstract class.
The abstract concept of design?
Abstract classes are often used to characterize the abstract concepts we derive in the analysis and design of problem areas, and are abstractions of a series of concrete concepts that look different, but are essentially the same .
For example, if we develop a graphical editing software, we will find that there are some specific concepts of circle and triangle in the problem domain, they are different, but they all belong to the concept of shape , the concept of shape does not exist in the problem domain, it is an abstract concept .
Cannot instantiate?
Abstract classes used to characterize abstract concepts cannot be instantiated because abstract concepts have no corresponding specific concepts in the problem domain.
Two kinds of mechanisms for implementing abstract classes in Java: Abstractclass & Interface
At the grammatical level, compare:
Abstract class demo{
abstract void method1 ();
Void method2 (); All member methods may be abstract or non- abstract
}
Interface demo{
Static final int I; The data member must be a static final type
(Abstract) void method1 (); All the member methods are abstact
}
On the programming:
Abstract class: Inheritance relationship, one class can only use one inheritance relationship
Can give method default behavior
Interface: A class can implement multiple interface
Method cannot have default behavior (behaves as code duplication in derived classes, which is not conducive to code maintenance)
The design concept:
Abstract class: Essentially represented as a class, so and inheritance (extends) is a relationship of "isa"
Interface: Just a contract implementation (implements)
http://www.ibm.com/developerworks/cn/java/l-javainterface-abstract/
Java abstract class