Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the knowledge points of Java polymorphism

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the knowledge points of Java polymorphism". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn what are the knowledge points of Java polymorphism.

1. The practice of treating a reference to an object as a reference to its base class object is called "upcasting".

2. The upward transformation makes the method simple. It only accepts the base class reference as a parameter, regardless of the particularity of the subclass. The specific operation of each subclass is realized by polymorphic dynamic binding.

3. Associating a method call with the method body is called binding, the binding at compile time is called early binding, and the binding at runtime is called late binding or dynamic binding or runtime binding. Process-oriented languages (such as C) can only perform pre-binding, except for static and final methods (private methods belong to final) in Java.

4. Polymorphism is implemented by late binding

5. It is special to pay attention to the overloading of private methods

[@ more@]

6. As long as there is an abstract method (abstract method) in a class, it must be defined as an abstract class (abstract class). Otherwise, there are compilation errors, and the abstract class cannot derive an instance. If there is a compilation error, it inherits from the subclass of the abstract class. If a definition has been provided for each abstract method, it can become an ordinary class, otherwise it will still be an abstract class.

7. The calling order of the constructor: a. Recursively call the base class constructor, from the hierarchical root class to the current class; b. The inner composite class calls the constructor in the order of declaration; c. Call the constructor of this class; note that b. It is in c. Before, Mr. becomes an instance of an internal composite class, and then officially begins to build an instance of this class.

8. When overloading the dispose () method of a subclass, remember to call the dispose () method of the base class, otherwise the cleanup action of the base class will not occur, that is, super.dispose () must be explicitly called in the dispose () method.

9 、 a. Initialize the storage space allocated to the object to binary zeros before anything else happens.

b. As mentioned earlier, the base class constructor is called. At this point, the overloaded draw () method is called (yes, before the RoundGlyph constructor is called), and because of step (1), we will find that the value of radius is 0.

c. The initialization code of the member is called in the order in which it is declared.

d. Calls the constructor body of the exported class.

10. the rules for writing the constructor: use the simplest possible method to make the object normal and, if possible, avoid calling other methods; calling dynamically bound methods in the constructor may cause serious errors

11. Inheritance is used to express differences between behaviors, and attributes are used to express changes in state (such as state pattern).

12. After the downward transformation of the parent class object, the subclass method is called. If there is no such method in the parent class, a compile-time error will occur.

13. Polymorphism must be dynamically bound, otherwise it is not polymorphic

At this point, I believe you have a deeper understanding of "what are the knowledge points of Java polymorphism?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report