Inheritance of Static Methods in Java
Despite the claim that static methods are not inherited in Java, code demonstrates the contrary. This contradiction raises the question: are static methods truly inherited?
To understand this apparent paradox, it's essential to revisit the concept of member inheritance in Java. According to the book, accessible members of a superclass (without using "super") are considered inherited.
However, the Sun Java Tutorials provide a broader perspective:
Based on this, static methods are inherited because they are inherently public. They are accessible by their simple names and are not bound to specific instances.
The only peculiarity with inherited static methods is their behavior when new static methods with identical signatures are introduced in subclasses. In this case, the existing static method is hidden, not overridden. This behavior ensures that the static implementation specific to the subclass remains unaffected.
Therefore, the book's explanation of member inheritance applies to both instance and static methods, with the distinction that static methods are always visible and inherited if they are accessible in the superclass. Furthermore, accessing a hidden static method depends on whether the invocation occurs from the superclass or subclass.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3