search
HomeJavaJavaBaseCan static properties and static methods in Java be inherited?

Can static properties and static methods in Java be inherited?

Jan 16, 2020 am 09:52 AM
javainheritstatic propertiesstatic method

Can static properties and static methods in Java be inherited?

Conclusion:

Static properties and static methods in Java can be inherited, but they are not overwritten, but hidden.

Cause analysis:

1. Static methods and attributes belong to classes. When calling, they can be completed directly through class name.method name, no need The inheritance mechanism can then be invoked.

If static methods and attributes are defined in the subclass, then the static methods or attributes of the parent class are called "hidden" at this time. If you want to call the static methods and properties of the parent class, you can directly use parent class name.method or variable name. As for whether to inherit, subclasses can inherit static methods. and properties, but they are not the same as instance methods and properties. There is such a situation as "hidden".

(Online learning video tutorial sharing: java video tutorial)

2. The reason why polymorphism can be realized depends on inheritance, interface and rewriting and overloading (inheritance and rewriting are most critical). With inheritance and overriding, references from the parent class can point to objects of different subclasses.

The function of rewriting is: after "rewriting", the priority of the subclass is higher than the priority of the parent class, but "hiding" does not have this priority.

3. Static properties, static methods and non-static properties can be inherited and hidden but cannot be overridden. Therefore, polymorphism cannot be achieved, and references from parent classes cannot point to objects of different subclasses. Non-static methods can be inherited and overridden, thus enabling polymorphism.

Recommended related articles and tutorials: java introductory tutorial

The above is the detailed content of Can static properties and static methods in Java be inherited?. 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

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor