1. Abstract classes and abstract methods
1.1 Abstract methods, only method declarations have no method body
Abstract class abstractclass{ abstractvoid// No {} }
1.2 To have one or more abstract methods, it must be an abstract class, and abstract classes can have no abstract methods.
1.3 Abstract classes can have no abstract methods, or can only implement methods.
Abstract class abstractclass{ void g () { System.out.println ("Hello");} }
1.4 Inherit the abstract class, to overwrite all abstract methods within the abstract class, to provide the method body, if you do not provide a method body then this subclass is also an abstract class, the preceding will be added keyword
2. Interface
There is no specific implementation within the 2.1 interface, and there is no method body.
Method default public permissions in the 2.2 interface
2.3 Interfaces can have domains, but are implicitly set to static and final
2.4 Interface permissions are public as well as classes, but must be in a file of the same name
3. Covariant Type:
- The overridden method in a subclass returns a type that can be a subtype of the return value of a parent class method
classA {}classBextendsA {}Abstract classAbstractClass {AbstractA g ();}classCextendsAbstractClass {//The return value type is type a//A g () {//return null; // } //g () The return value type is a subtype of type B can also overwriteB g () {return NULL; }}4. Multiple inheritance
4.1 Interface extends interface, interface, interface, ...
4.2 Class extends interface, interface, interface, ...
Class 4.3 extends class implements interface, interface, interface, ...
4.4 Class implements interface, interface, interface, ...
- Implement multiple interfaces in which you should avoid having the same method name
5. Nested interfaces
- Interfaces can be nested within a class or in other sockets
5.1 The nested interfaces/classes are treated outside Class A as data members of Class A, as normal interfaces/classes within Class A
Class or interface permissions that are nested in class 5.2 can be private
5.3 An interface in an interface cannot be declared as private because the method in the interface is default public
5.4 The private interface in a nested function is to make the method in this private interface has no return type and cannot be transformed upward
class A { public class ain{ } // internal class permission can be set to private Privateclass ain2{ } publicinterface aface{ } privateinterface aface2{ void // must return a null value } }
6. Interface and Factory
Java Programming thought Note Nineth Chapter interface