Exploration on whether the subclass of Java programming can override the static method of the parent class

Today, I suddenly discussed the static method of subclass inheriting parent class. Some people insist that it can be written, others say that it can not be rewritten. Can it be written? This question is very simple. Just test it.

First, the parent class code:

The following is the subclass Code:

The output is:

Let me take it as like as two peas. The static method of the parent class can not be inherited by subclasses, let alone rewrite. Even if there is a static method exactly like the parent class in the subclass, it is also the subclass itself, and the static method of the parent class is not the same thing. Methods that are static belong to classes and not objects.

Add: because the last problem discussion aroused the enthusiasm of many people, the final result was agreed by everyone. The above is my previous point of view. There are some errors. The following is the final discussion result: the static methods of the parent class can be inherited by the subclass, but can not be rewritten. The result was finally accepted by everyone.

The above is all the content of this article on whether the Java programming subclass can override the static method of the parent class. I hope it will be helpful to you. Interested friends can continue to refer to this site: examples of static internal class methods implemented in Java singleton mode, detailed explanation of java development basic date class code, etc. you can leave a message at any time. Welcome to exchange and discuss. Thank you for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>