Discussion on the inheritance of static variables and static methods in Java
If the learning is not clear or unclear, is to do some tests, and try it yourself, this time I will do a static variable inheritance and static method of inheritance problems test.
First, I'll build a parent class:
So I'm building a sub-class:
When these are all ready, I create the object for the subclass and then use the class name. static/static methods and object names. static/static variables test the results of their output.
Such output types are:
So the result I output is:
so to summarize:
1. The static and static methods in the subclass are called by the class name, and when the parent class is the same as the child class, the subclass hides the same static and static methods in the parent class, and if there are no static and static methods in the subclass that are identical to its parent class, the static and static methods that the subclass inherits from its parent class are displayed.
2. Create objects from subclasses to call static and static methods in subclasses with object names, except static and static methods that are not in the parent class, and display static and static methods for their subclasses. Otherwise, the final display must be a static variable and a static method from where the parent class is referenced.
Discussion on the inheritance of static variables and static methods in Java