Java-polymorphism, internal class, java-polymorphism,

Source: Internet
Author: User

Java-polymorphism, internal class, java-polymorphism,

1. Polymorphism:

1) meaning:

1.1) when a reference of the same type points to different objects, there are different implementations ------- behavior polymorphism: cut (), run (), teach ()...

1.2) the same object has different functions when it is modeled into different types ------- object polymorphism: Me, you, water...

2) upward shape:

2.1) references of the parent type point to the object of the subclass.

2.2) the following types can be modeled: parent class + Implemented interfaces

2.3) What can be clicked to see the reference type

3) Forced type conversion. There are only two successful conditions:

3.1) the referenced object is of this type.

3.2) the interface is implemented by referencing the object to which the object is pointed.

4) if the forced conversion does not meet the preceding two conditions, the ClassCastException type conversion exception occurs.

Suggestion: Use instanceof to determine whether the referenced object is of this type before strong conversion.

2. member Internal classes: ----- low actual application rate

1) Class middle-end class. The Outer class is called the Outer external class, and the inside class is called the Inner internal class.

2) Internal classes generally only serve external classes and are invisible to external users.

3) internal class objects can only be created in external classes.

4) The internal class can directly access members of the external class (including private). An implicit reference in the internal class points to the external class object that creates it.

External class name. this.

3. Anonymous internal class:

1) If you want to create an object of A Class (subclass), and you only need to create one object, this class does not need to be named, it is called an anonymous internal class.

2) access external variables in internal classes. The variables must be final

 

I am a beginner. If any updates are poor, I would like to thank you!

More highlights will be updated later!

Related Article

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.