java--multiplexing Code, composition, Inheritance (Java programming Idea)

Source: Internet
Author: User

Reusing code is one of the many compelling features of Java.

You can reuse code by creating a new class without having to write from scratch. The trick of this approach is to use classes without breaking existing program code. There are two ways to achieve this.

The first is very intuitive: you only need to produce an object of an existing class in the new class. Because the new class is made up of objects that have existing classes, this method is called a combination . This method simply re-uses the functionality of the existing program code, not its form.

The second method is a little more nuanced, and it creates a new class according to the type of the existing class. Instead of changing the form of an existing class, take the form of an existing class and add new code to it. This magical approach is called inheritance , and the compiler can do most of the work.

In terms of composition and inheritance, new types are generated using existing classes.

Focus on the code: toString, extends

  

java--multiplexing Code, composition, Inheritance (Java programming Idea)

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.