search
HomeJavaJavaBaseThe difference between interface and abstract class in java

The difference between interface and abstract class in java

Abstract class          (Recommended learning: java course)

Abstract classes must be used Modification, the subclass must implement the abstract method in the abstract class. If there are unimplemented methods, the subclass must also be decorated with abstract. The default permission modifier of an abstract class is public, which can be defined as public or procted. If it is defined as private, subclasses cannot inherit it. Abstract classes cannot create objects

The difference between abstract classes and ordinary classes

Abstract classes must be modified with public and procted (if modified with private, subclasses cannot inherit , and its abstract method cannot be implemented). The default is public

Abstract classes cannot create objects

If a subclass inherits an abstract class, it must implement all its abstract methods. If there are unimplemented abstract methods, they must be defined as abstract

Interface

The variables in the interface are implicitly modified with public static final, and an initialization needs to be given value.

The method is implicitly modified with public abstract (and it can only be public. If it is private or procted, an error will be reported during compilation).

Methods in interfaces cannot have specific implementations by default (default implementations are available starting from JDK1.8)

The difference between interfaces and abstract classes

Abstract classes can only be inherited once, but can implement multiple interfaces

Interfaces and abstract classes must implement all methods in them. If there are unimplemented abstract methods in the abstract class , then the subclass also needs to be defined as an abstract class. Abstract classes can have non-abstract methods

Variables in the interface must be modified with public static final, and an initial value needs to be given. So the implementation class cannot be redefined, nor can its value be changed.

The methods in the interface default to public abstract and can only be of this type. It cannot be static. Methods in interfaces are not allowed to be overridden by subclasses. Static methods are allowed in abstract classes.

The above is the detailed content of The difference between interface and abstract class 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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment