Java casual interface and java casual Interface
/*
* Interfaces can be divided into: Dumb interfaces, abstract interfaces, and interface classes.
* Dumb interface: public and protected (note that protect has the package permission and only this package opens the interface) Method
* Abstract interface: the dummy interface is changed to an abstract method, and the abstract method is appended before.
* Interface Class: it is the class declared by the interface (it is essentially a class that can be inherited and can be converted up)
* Interface
* Interface classes are divided into abstract classes rather than abstract classes.
* Non-abstract class:
* All the methods in the interface are public (protect cannot be modified), but the interface itself has the package access permission.
* The fields are both final and static, meaning they cannot be inherited or reloaded. They only have one memory.
* The interface can be converted up, which directly produces polymorphism and is convenient for message loops.
* Abstract class: Add abstarct to the interface class.
* The only difference is that the abstract interface class cannot have a domain.
**/
Public class MyInterface {
Public static void main (String [] args ){
Man man = new Man ();
Man. run ();
// Simple proxy adapter Mode
Delegate de = new Delegate ();
De. run (new Adapter (man ));
}
}
Abstract interface action {
Void run ();
}
Abstract class Human {
Abstract void shape (); // The abstract class must be declared in the abstract method.
Human (){
System. out. println ("Human ()");
}
}
Class Man extends Human implements action {
Void shape (){
// TODO Auto-generated method stub
System. out. println ("man. shape ()");
}
Man (){
System. out. println ("man ()");
Shape ();
}
Public void run (){
// TODO Auto-generated method stub
System. out. println ("man. run ()");
}
}
Class Man2 extends Human implements action {
Void shape (){
// TODO Auto-generated method stub
System. out. println ("man2.shape ()");
}
Man2 (){
System. out. println ("man2 ()");
Shape ();
}
Void sex () {// Add a gender Method
}
Public void run (){
// TODO Auto-generated method stub
System. out. println ("man2.run ()");
}
}
Class Delegate {// proxy action
Void run (action act ){
Act. run ();
}
Delegate (){
}
}
Class Adapter implements action {// adapt the object to action
Action act;
Adapter (Object obj ){
Act = (action) obj; // make full use of the upward conversion polymorphism of the interface
}
Public void run (){
// TODO Auto-generated method stub
Act. run ();
}
}