Java interface, Lambda learning

Source: Internet
Author: User

    1. implementation of the interface : use interface definition: The form is as follows          
1 Interface printable{2     Final int MAX = +; 3     void Add (); 4     float sum (floatfloat  y); 5 }

Interface interface Name {interface Body}, in which the interface body is only abstract methods and constants of the declaration, constants are public static type, methods are public type, the above interface printable can be expressed in the following form:

 1  interface       printable{ 2  public  final  static  int  max= 100 3  public   Abstract  void   add ();  4  public   Abstract  float  sum (float  X,float   y);  5 } 

To implement an interface with a class, the sample code is as follows:

1  Public Interfacecomputable{//Declaration Interface Computable2     intMAX = 46;3     intFintx);4 }5 6  Public classChinaImplementscomputable{//The China class implements the interface7     intNumber ;8      Public intFintx) {//overriding the interface F method public note9         intsum = 0;Ten          One          for(inti = 1; I <= x; i++){ Asum = sum +i; -         } -  the         returnsum; -      } - } -  +  Public classCalmaxImplementscomputable{ -     intNumber ; +      Public intFintx) { A         returnMAX +x; at     } -}

Java interface, Lambda learning

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.