Home  >  Article  >  Java  >  What are the classes that cannot be inherited in Java?

What are the classes that cannot be inherited in Java?

尚
Original
2019-12-26 16:34:055069browse

What are the classes that cannot be inherited in Java?

The class marked final in JAVA is the final class and cannot be inherited, such as: public, final, String.

Introduction to JAVA inheritance:

Inheritance is the most significant feature of object-oriented. Inheritance is to derive new classes from existing classes. , new classes can absorb the data attributes and behaviors of existing classes, and can expand new capabilities.

Java inheritance is a technology that uses the definition of an existing class as a basis to create a new class. The definition of a new class can add new data or new functions, or use the functions of the parent class, but You cannot selectively inherit from parent classes.

Modified class When using final to modify a class, it means that the class cannot be inherited.

Note: a. For a class modified by final, the member variables in the final class can be designed as fianl according to your actual needs. b. Member methods in final classes will be implicitly designated as final methods.

Note: When designing a class, you must think carefully about whether this class will be inherited in the future. If it can be inherited, the class cannot be modified with fianl. Here, generally speaking, we use tool classes It is often designed as a fianl class. In the JDK, the classes designed as final include String, System, etc.

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

The above is the detailed content of What are the classes that cannot be inherited 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