Java uses internal classes to implement multiple inheritance

Source: Internet
Author: User

 

 
Multiple inheritance relationships can be achieved using internal classes:
As follows:

Class D {}
Abstract class E {}
Class Z extends d {
E makee () {return New E (){};}
}

Public class multiimplementation {
Static void takesd (d ){}
Static void takese (E ){}
Public static void main (string [] ARGs ){
Z = new Z ();
Takesd (z );
Takese (Z. makee ());
}
}
As shown above: Multi-inheritance can be implemented.
Benefits of internal classes:

1. The internal class can have multiple instances, each of which has its own status information and its peripheral class
The information of the image is independent of each other.
2. In a single peripheral class, you can allow multiple internal classes to implement the same interface in different ways, or
The same class. This example will be displayed later.
3. Creating internal class objects does not depend on creating peripheral class objects.
4. The internal class has no confusing "is-a" relationship; it is an independent entity.

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.