Alibabacloud.com offers a wide variety of articles about how to achieve polymorphism in java, easily find your how to achieve polymorphism in java information here online.
Understanding Java Polymorphism
Author: mienflying Date: 2006-08-19This article from Blogjava, I found that the author of the original Flyingis write very well, very in place, turned over, he was lazy to write ... Thank you for that.
These days I am reviewing the basics of Java language, although with the team, the individual has carried out the actual project
parent class4) Call the overridden methodAdd: Static polymorphism is called method overloading3. SupplementType conversion instanceofWe are using employee salary = new Salary ("", 1, "", 2,200000);The Salary s2 = (salary) salary, but the downward conversion,But we don't know if it's right after conversion.System.out.println (Salary instanceof Employee); TrueSystem.out.println (Salary instanceof salary); TrueSystem.out.println (Salary instanceof Hourl
polymorphicEncapsulation creates a new data type by merging features and behaviors.The function of polymorphism is to eliminate the coupling relationship between types.method Call BindingDefinition: Associating a method invocation with the same method topic is called a binding.Binding before the execution of the program (if any, implemented by the compiler and linker) is called early binding. Binding is called late binding, or binding at execution tim
Polymorphism:Java's method overloading is that you can create multiple methods in a class that have the same name but have different parameters and different definitions. The methods used to determine which method to use in Java are overridden by the number of different arguments and parameter types passed to them when invoking the method, that is, the subclasses may have other special definitions of the methods in the parent class, and the contents o
We used classes to create new types (type) and use inheritance to facilitate the process of creating classes. I will delve into the type in this talk and introduce the concept of polymorphism (polymorphism). type CheckAny of the variables and references in Java are declared in type declaration tobe used. We've seen object data, class data, method parameters, meth
Polymorphism--concepta multi-state refers to a reference (type) A variety of states in different situations. It can also be understood that polymorphism refers to a method that is implemented in a different subclass by pointing to a pointer to the parent class.There are two ways to implement polymorphism:1, inheritance, 2, interface
In object-oriented programming languages, polymorphism is the third basic feature after data abstraction and inheritance.
8.1 further upward Transformation
8.2 Transfer
Associating a method call with a method subject is called binding. If binding is performed before the program is executed (if any, implemented by the compiler and the Connection Program), it is called pre-binding.
Post-binding: It means to bind objects according to their types at runti
Java Polymorphism is one of the three main features of object-oriented. (Encapsulation, inheritance, polymorphism), which refers to the specific type of reference variable defined in the program and the method call made by the reference variable are not deterministic during programming, but are determined during the program's run, that is, the instance object of
) a;//The animal A, down to the Cat Cc.fun ();//Downward transformation purposes: is to use a method that is unique to subclasses/*animal d = New Animal (); * Animal F = new Dog (); * Cat G = (cat) F;cat e = (cat) D; This type is not allowed, the small animal must be a cat */}}Note: For transformation, the sub-class object is being transformed from start to finish: The Cat object transforms into an animal and transforms into a cat.PS: Transformation is purposefulPractice: /* * BLF and BLF2 's
modify the Lady Class code.For example, the parent class animal, subclass Dog, Method Sing (). class Animal {Public void sing(A) ;} class Dog extends Animal {Public void sing(B) ;} Public class Test {Animal A =NewDog ();//Parent reference variable a points to child object dog, which will now be transformed upwardA.sing ();//Use the parent class reference variable A to refer to the overridden method sing (), which is dynamically bound to the dog's Sing () when executed}Reprint Please specif
In C ++, if the front side of the function in the parent class is marked with virtual, polymorphism occurs.
If the parent class func is virtual
Super * P = new sub ();
P-> func (); // call the func of the subclass.
If it is not virtual, p-> func will call the original function of the parent class.
In Java, no matter whether you write or not write the virtual code, the function with the same name as the sub
In the Java language, polymorphism is mainly represented by the following two ways:
1, the method of overloading. Overloading means that there are multiple methods with the same name in the same class, but these methods have different parameters, so at compile time you can determine which method to call, which is a compile-time multiple. Overloading can be thought of as a method
to display the required type conversion, Java can automatically perform:
Public ClassTest {Public Static VoidMain (string [] ARGs ){IntA = 3;DoubleB; B=A;// Widening ConversionSystem. Out. println ();}}
Basic type conversion
Upcast and Polymorphism
In Java, references can also be converted to types, but there are restrictions.
We canConversi
Source: http://www.cnblogs.com/mengdd/archive/2012/12/25/2832288.htmlThe concept of polymorphism polymorphic = = Late binding .Do not interpret function overloading as polymorphic.Because polymorphism is a run-time behavior, not a compile-time behavior.Polymorphic: A reference to a parent type can point to an object of a subtype.For example, Parent p = new Child (); When calling a method using polymorph
Run-time polymorphism is one of the most powerful mechanisms for object-oriented programming code reuse, and dynamic concepts can be said to be "an interface, multiple methods". The basis of Java implementation Run-time polymorphism is dynamic method scheduling, which is a mechanism to invoke overloaded methods at runtime rather than at compile time, and then dis
As an object-oriented language, Java has three characteristics: encapsulation, inheritance and polymorphism. Polymorphism is allowing objects of different classes to respond to the same message. Based on polymorphism, some types of coupling relationships can be eliminated, which can be substituted and expandable. The m
set. Let's take a look at the polymorphism problem in the set below, which is the core of this article.
We know that polymorphism in Java means that the type of a reference variable defined in a program and the called method cannot be determined during encoding, it can only be determined during running. Simply put, the reference variable you define is of the par
Java study NOTE 4: Several corners of static and small talk about polymorphism, learning notes static
There are a few things recently. If you haven't updated your notes in time, you can't discard your studies. To sum up the recent studies, the focus is on some static applications. polymorphism is a design concept that is easy to understand, it is not easy to t
A⑥a and D⑦b and B⑧b and B⑨a and D(iv) Analysis①②③ better understand, generally will not be wrong. ④⑤ is a bit confused, why is not the output of "B and B" it?! Let's go back to polymorphism.Runtime polymorphism is one of the most powerful mechanisms for object-oriented programming code reuse, and the concept of dynamic can also be said to be "one interface, multiple methods". Java's implementation of runtime poly
Java object-oriented three magic weapon: encapsulation, inheritance, polymorphism (abstract)Inherited:1. Improved code reuse rate2. Let the class and the class have a relationship, with this relationship, there is a polymorphic characteristicsNote: Do not inherit in order to get the functionality of other classes, simplify the code,You must have an owning relationship between the class and the class to inhe
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.