The 10th Chapter Polymorphic

Source: Internet
Author: User

The 10th Chapter Polymorphic

This chapter focuses on:
1. polymorphic
2. Dynamic binding and static binding
3. Super class

Polymorphism means having many forms.
In the Java language, polymorphism is mainly about having the same form, but different parameters implement different functions.

Polymorphic Rules:
1, the method name must be the same.
2, incoming parameter type must be the same.

Public class student{
int x;
int y;
int z;

void print (int x) {
SYSTEM.OUT.PRINTLN (2 * x);
}
void Print (int x, int y) {
SYSTEM.OUT.PRINTLN (2 * x + y);
}
Public static void Main (string[] args) {
Student st = new Student ();
St.print (2);
St.print (2, 3);
}
}

Inheritance and polymorphism:

public class studenta{
void print () {
system.out.println ("This is a method");
}
public static void Main (string[] args) {
studenta sta = new Studenta ();
studentb STB = new Studentb ();
sta.print ();
stb.print ();
}
}

Class Studentb extends studentap{
void print () {
System.out.println ("This is a subclass");
}
}

The so-called binding is the binding of the object handle to the method.
Bindings are divided into static bindings and dynamic bindings.
There is no polymorphic problem with static bindings.
There is a polymorphic problem with dynamic binding.

Use of the Equals method:
1, the reflexive nature.
2, symmetry.
3, transmission.
4, consistency.

Overloading: A method that has the same name but different parameters in a class.
Polymorphism: Avoid overloading in the parent class, which causes the code to be bloated and difficult to maintain.
Two forms of polymorphism: overloading and covering.

The 10th Chapter Polymorphic

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.