Java casual interface and java casual Interface

Source: Internet
Author: User

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 ();
}

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.