Differences between extends and implement in Java

Source: Internet
Author: User

Simply put:
1.extends is inherited from the parent class, as long as the class is not declared final or the class is defined as abstract to inherit,
Multiple inheritance is not supported in 2.JAVA, but can be implemented with interfaces, which will use the implements,
3. Inheritance can inherit only one class, but implements can implement multiple interfaces, separated by commas,
Like class A extends B implements C,d,e

In terms of words:
extends inherits the class; implements implements the interface.


Classes and interfaces are different: there are programs implemented in the class, and interfaces are not implemented, only predefined methods can be

Java also provides an inheritance mechanism, but also provides a concept called interface. Since Java's inheritance mechanism can only provide single inheritance (that is, only one parent category), Java's interface is substituted for C + + 's multiple inheritance. Interface is a kind of interface, which specifies the two objects to communicate, and what are the specifications of the communication.

As seen in the Java programming language,,java's interface says:

Some functions or data members are common to other objects belonging to different categories, then the functions are defined in a interface with the data members, and then all the different classes of Java objects can be used together.
Java class can inherit only one parent class (with the extends keyword), but it can have (or do) many interface (with implements keywords).

What's the difference between extends and implements?
For class, extends is used for (single) inheritance of a class, and implements is used to implement an interface (interface).

The introduction of interface is to partially provide multiple inheritance functions. Only the method header is declared in interface, and the method body is left to the implementation class. Instances of these implementations of class can be treated as instances of interface. The relationship between interface can also be declared as extends (multiple inheritance).

Note: A interface can extends multiple other interface.

Differences between extends and implement in Java

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.