Java learning: white box reuse and black box reuse

Source: Internet
Author: User

Java learning: white box reuse and black box reuse

1. white box reuse: This is also called inheritance reuse. Child classes inherit all the things of the parent class,

To some extent, white box reuse destroys encapsulation. Is a relation of is.

Example: class Liucy {

Public voidteachCpp () {System. out. println ("Teach Cpp ");}

Public void chimogu (){}

}

Class Huxy extends Liucy {}

2. Black Box multiplexing: it is also called combination multiplexing, which is a kind of has a relationship.

Example: class Liucy {

Public voidteachCpp () {System. out. println ("Teach Cpp ");}

Public void chimogu (){}

}

Class Huxy {

Private Liucy liucy = new Liucy ();

Public void teachCpp () {liucy. teachCpp ();}

}

Principle: Combination reuse replaces inheritance reuse.

This gives us the opportunity to select this reusable feature.

The best java training institution in Shanghai ziqin, free of charge! Employment and base salary protection to solve all students' concerns: http://www.shziqin.net/gqindex.aspx


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.