In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the "overloading, rewriting, polymorphism, static binding and dynamic binding in Java related content and concept introduction", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "Java overloading, rewriting, polymorphism, static binding and dynamic binding related content and concept introduction" bar!
Overloading, whose English name is overload, means that more than one method with the same name is defined in a class. The number, type and order of parameters of these methods cannot be the same. The return type can be the same or different.
Public class TstaticOverload {static int height; TstaticOverload () {System.out.println ("Planting a seedling"); height = 0;} TstaticOverload (int initialHeight) {height = initialHeight; System.out.println ("Creating new Tree that is" + height + "feet tall") } static void info () {System.out.println ("Tree is" + height + "feet tall");} static void info (String s) {System.out.println (s + ": Tree is" + height + "feet tall") }} public class testSO {public static void main (String [] args) {TstaticOverload t = new TstaticOverload (5); TstaticOverload.info (); TstaticOverload.info ("overloading method"); new TstaticOverload ();}} out: Creating new Tree that is 5 feet tall Tree is 5 feet tall overloading method: Tree is 5 feet tall Planting a seedling
Rewriting, the English name is override, refers to in the case of inheritance, the subclass defines a method with the same name, the same return type or compatible type and the same parameters as the method in the base class, which is called the subclass overrides the method of the base class. This is a necessary step to achieve polymorphism.
Polymorphism: polymorphism is the ability of the same behavior to have many different forms or forms.
Public class StaticSupper {public static String staticGet () {return "Base staticGet ()";} public String dynamicGet () {return "Base dynamicGet ()";}} class StaticSub extends StaticSupper {public static String staticGet () {return "Sub staticGet ()" } public String dynamicGet () {return "Sub dynamicGet ()";}} class StaticMub extends StaticSupper {public static String staticGet () {return "Mub staticGet ()";} public String dynamicGet () {return "Mub dynamicGet ()" }} public class StaticPolymorphism {public static void main (String [] args) {StaticSupper sup1 = new StaticSub (); System.out.println (sup1.staticGet ()); System.out.println (sup1.dynamicGet ()); StaticSupper sup2 = new StaticMub (); System.out.println (sup2.staticGet ()); System.out.println (sup2.dynamicGet ());} out: Base staticGet () Sub dynamicGet () Base staticGet () Mub dynamicGet ()
The concept of program binding:
Binding means that a call to a method is associated with the class in which the method is located (the method body). For java, binding is divided into static binding and dynamic binding, or pre-binding and late binding.
Static binding:
The method is bound before the program is executed, which is implemented by the compiler or other linker. For example: C.
For Java, it can simply be understood as a binding at the compile time of the program; in particular, the only methods in java are final,static,private and constructors that are pre-bound.
Dynamic binding:
Late binding: dynamic binding means that the compiler does not know which method to call at compile time until the runtime binds according to the type of the specific object.
If a language implements late binding, it must also provide mechanisms to determine the type of object at run time and call the appropriate methods respectively. In other words, the compiler still does not know the type of the object at this time, but the method invocation mechanism can investigate itself and find the correct method body. Different languages have different ways to implement late binding. But we can at least think of it this way: they all have to place some special type of information in the object.
Method overload static method overload and common method overload. Static method overloading is static binding, and method calls are made through: class name. Method. Ordinary method overloading is dynamic binding, method call is through: instance object reference. Method. The constructor can be overloaded, but cannot be overridden.
Static methods can be overridden, but there is no polymorphic effect.
Thank you for your reading, these are the contents and concepts of overloading, rewriting, polymorphism, static binding and dynamic binding in Java. After the study of this article, I believe you have a deeper understanding of the introduction of the relevant contents and concepts of overloading, rewriting, polymorphism, static binding and dynamic binding in Java. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.