search
HomeJavaJavaBaseThe difference between interface and inheritance in java

The difference between interface and inheritance in java

Dec 30, 2019 pm 03:08 PM
javainterfaceinherit

The difference between interface and inheritance in java

Interface (English: Interface) is an abstract type in the JAVA programming language and is a collection of abstract methods. Interfaces are usually declared with interface. A class inherits the abstract methods of the interface by inheriting the interface.

Inheritance is a cornerstone of Java object-oriented programming technology because it allows the creation of hierarchical classes. Inheritance means that a subclass inherits the characteristics and behaviors of the parent class, so that the subclass object (instance) has the instance fields and methods of the parent class, or the subclass inherits methods from the parent class, so that the subclass has the same behavior as the parent class.

Recommended: java video tutorial

The difference between java interface and inheritance:

1. Different modifier modifications ( interface), (extends)

2. Multiple inheritance is possible in object-oriented programming! However, only multiple inheritance of interfaces is supported, and multiple inheritance of 'inheritance' is not supported. Inheritance has single root in java. Subclasses can only inherit from one parent class.
3. Only global constants and abstract methods can be defined in interfaces, while attribute methods, variables, constants, etc. can be defined in inheritance.

4. When an interface is implemented by a class, the abstract method in the interface must be implemented in the class, and if the inheritance wants to call that method, call that method.

5. Multiple inheritance is not supported in JAVA, but it can be implemented using interfaces, so you need to use implements

6. Inheritance can only inherit one class, but implements can implement multiple interfaces. , just separate them with commas.

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of The difference between interface and inheritance in java. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor