search
HomeJavaJavaBaseThe difference between java interface and abstract class

The difference between java interface and abstract class

Interface

Concept

An interface is a collection that encapsulates certain functions. To abstract a type of behavior, use interface modification. (Recommended learning: java course)

public interface InfClass {
    public void say();
}

Abstract class

Concept

In short , a class containing an abstract method is an abstract class. An abstract method only has a method body and no implementation. It is modified with abstract.

abstract class AbsClass {
    abstract void say();
}

Java provides and supports the creation of abstract classes and interfaces. Their implementations have something in common, but the difference is:

All methods in the interface are implicitly abstract. An abstract class can contain both abstract and non-abstract methods.

A class can implement many interfaces, but it can only inherit one abstract class

A class does not need to implement all methods declared by abstract classes and interfaces , of course, in this case, the class must also be declared abstract.

Abstract classes can implement interfaces without providing implementations of interface methods.

Variables declared in the Java interface are final by default. Abstract classes can contain non-final variables.

Member functions in Java interfaces are public by default. Member functions of an abstract class can be private, protected or public.

Interfaces are absolutely abstract and cannot be instantiated, and abstract classes cannot be instantiated.

If a class implements an interface, it must implement all methods of the interface, and abstract classes do not necessarily

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

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

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.

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.

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.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.