Basic Java Learning 18

Source: Internet
Author: User

The polymorphism of the class:


The polymorphism of a subclass object: a reference to a parent class to a subclass (an instance of a subclass is assigned to a parent class)

person P1 = new Man ();//upward transformation (equivalent to automatic conversion of basic data types)

Virtual method invocation: Refers to the object entity of the subclass through a reference to the parent class, and when the method is called, the child class is actually executing the method of overriding the parent class

P1.eat ();

P1.walk ();


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/75/49/wKioL1Y0scGS7y73AAGJ7mEs8kU461.jpg "title=" Polymorphism. png "alt=" wkiol1y0scgs7y73aagj7mes8ku461.jpg "/>


Transformation mechanism of Child parent class object: (Analogy to basic data type conversion mechanism)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/75/4B/wKiom1Y0sZugaqySAAE2EcTfznU683.jpg "title=" Child parent class object conversion. png "alt=" wkiom1y0szugaqysaae2ectfznu683.jpg "/>


Basic Java Learning 18

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.