Access to domains and static methods based on Java does not have polymorphism (example explanation)

1. Associating a method call with a method body is called

2. Compile time binding (static) determines the type of reference object at the program compilation stage

3. Runtime binding (dynamic binding) refers to judging the actual type of the referenced object during execution and calling its corresponding methods according to its actual type

4. Except static method and final method (private method belongs to final method), all other methods are late bound. All methods in Java implement polymorphism through dynamic binding

5. The behavior of accessing a domain is not polymorphic

Output results:

sup. field = 1,sup. getField() = 2 sub.field = 2,sub.getField() = 2,sub.getSuperField() = 1

When the subfield object is transformed into a super reference, any field access operation will be resolved by the compiler, so it is not polymorphic. The subfield actually contains two fields called fields: its own and inherited from the superfield

Usually, the domain is set to private, which cannot be accessed directly or inherited. It can be accessed by calling methods

6. Accessing a static method has no polymorphism and is not associated with a single object

Output results:

Super staticMethod() Sub staticMethod()

The above article is based on the fact that the access to domains and static methods in Java is not polymorphic (example explanation), which is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.

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
分享
二维码
< <上一篇
下一篇>>