Java Learning--interface interface

Source: Internet
Author: User

Interface: Initial understanding can be thought of as a special abstract class
When a method in an abstract class is abstract, the class can be represented by an interface.
Class is used to define classes
Interface for defining interfaces

When the interface is defined, the format features:
1, the constants in the interface are defined: constants, abstract methods.
2, the members in the interface have fixed modifier symbols
Constants: public static final
Method: Public Abstracts

Remember: The members in the interface are public

Interface: It is not necessary to create an object, because there is an abstract method.
Subclasses are required to implement a subclass that can be instantiated only after the abstract methods in the sub-class docking port have all been overwritten.
Otherwise, the subclass is an abstract class.


Interfaces can be implemented in many classes. It is also a form of conversion that is not supported for multiple inheritance. Java supports multiple implementations.

Features of the interface:
An interface is a rule that is exposed externally.
An interface is a function extension of a program.
Interfaces can be used to implement multiple implementations.
A class is an implementation relationship between interfaces, and a class can inherit a class and implement multiple interfaces at the same time.
There can be an inheritance relationship between an interface and an interface.

Interfaceinter{ Public Static Final intNUM = 3;  Public Abstract voidshow ();}Interfaceintera{ Public Abstract voidmethod;}classdemo{ Public voidfunction () {}}classTestextendsDemoImplementsinter,intera{ Public voidShow () {} Public voidmethod () {}}Interfacea{voidMethodA ();}InterfaceBextendsa{voidMethodA ();}InterfaceCextendsb{voidMethodA ();}classDImplementsc{voidMethodA () {}voidMethodB () {}voidMethodA () {}}classInterfacedemo { Public Static voidMain (string[] args) {System.out.println ("Hello world!"); }}
/*class student{abstract void study (); void Sleep () {System.out.println ("Sleep")}//void Smoke ()//{//System.out.println ("Smokin    G "); }}interface smokoing{void Smoke ();} Class Zhangsan extends sudent implements smoking{void Stude () {} public void Smoke () {}}class Lisi extends student{ }*/classsporter{voidplay ();}Interfacestudy{}classWangwuextendsSportsImplements {}class  {     Public Static voidMain (string[] args) {System.out.println ("Hello world!"); }}

Java Learning--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.