Java Basics-Interface interface

Source: Internet
Author: User

An interface is a collection of abstract methods and constant value definitions, an interface is a special abstract class that contains only the definitions of constants and methods, without the implementation of variables and methods.

interfaces, interfaces: extends, class-A, class: Extends, Class-I interface: Implements

1. Interface can be multiple implementations

2. All variables of the interface are public static final types, which can be not written, default. Abstract of all methods of an interface can be omitted without writing

3. The interface can inherit other interfaces and add new attributes and abstract methods.

4. Multiple unrelated classes can implement the same interface

5. A class can also implement multiple unrelated interfaces

6. There is polymorphism between the interface and the implementation class

Keyword: implements

Public interface Valuable {public double Getmoney ();} Interface protectable {public void beprotected ();} Interface A extends protectable {void m (); void Getmoney ();} Abstract class Animal {private String name;abstract void Enjoy ();} Class Goldenmonkey extends Animal implements valuable, protectable {public double Getmoney () {return 10000;} public void beprotected () {System.out.println ("live in the");} public void Enjoy () {}public void Test () {Valuable v = new Goldenmonkey (); V.getmoney (); protectable p = (protectable) v;p.beprotected ();}} Class Hen implements A, valuable





}

  

Java Basics-Interface interface

Related Article

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.