The difference between extends and implements in PHP ____php

Source: Internet
Author: User
Tags inheritance

Extends is inheriting a class
Methods that can use the parent class after inheritance
You can also override methods of the parent class

Implements is the implementation of multiple interfaces
The method of the interface is generally empty
Must be overridden to use

Extends is inherited from the parent class, as long as that class is not declared final or the class is defined as abstract and can be inherited, multiple inheritance is not supported in Java, but it can be implemented using interfaces, which means that inheritance can only inherit a class, implements, But implements can implement multiple interfaces, separated by commas.
Like what
Class A extends B implements C,d,e

Extends inheritance class implements implementation interface

Classes and interfaces are different. A program is implemented in a class, and the interface has no program implementation, only the predefined method extends the inheriting class
Implements implementation interface
Java also provides an inheritance mechanism, but it also provides a concept called interface. Because the Java inheritance mechanism can only provide a single inheritance (that is, only one parent class can be inherited), it replaces the multiple inheritance of C + + with Java interface. Interface is a kind of interface, which stipulates the communication of two objects, which are the norms of communication. For example, the interface of,java in the Java programming language means that some functions or data members are shared by other objects belonging to different classes, and these functions are defined in a interface with the data member, Then let all the different classes of Java objects be used together.

So, for Java inheritance and interface,, we summarize the following:

The 1.Java class can inherit only one parent class (with the extends keyword), but can have (or implement) many interface (with the Implements keyword).
What is the difference between Q5.1 extends and implements?
A: For class, extends is used (single) to Inherit a class (class), whereas implements is used to implement
An interface (Interf
ACE).
Interface is introduced to partially provide multiple inheritance functions.
In interface, you simply declare the method header and leave the method body to the implemented class.
The instances of the class that are implemented can be treated as interface instances.
The relationship between interface can also be declared as extends (multiple inheritance).
Note that a interface can extends multiple other interface.


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.