Java Basics-Inheritance, abstract classes, interfaces

Source: Internet
Author: User

Inheritance and interfaces are two of the most important concepts in OOP programming languages, and often confuse programmers with their use. When to use inheritance better, when to use the interface better?

First of all, from the multi-state characteristics of OOP programming language, both are a manifestation of polymorphism. Inheritance is more focused on categorizing objects (inheritance systems) and interfaces focusing on classifying functional methods.

Each class belongs to a particular inheritance system, and all class-up conversions can eventually be turned into a single base class. Inheritance will "do what" and "how to" coupled together, if you need to reuse existing methods must add the new class to the existing inheritance system (or adopt wrapper class).

Interfaces can be "what" and "how to" separate, you can convert up to more than one base class.

Abstract classes are a buffer between interfaces and classes, and are a very important tool in the process of programming. Because we can't always use pure interfaces. For example, there is an interface a, if you use a pure interface method. A1,A2,A3 is all A's implementation class, if the A interface new or modified any old method will affect three implementation classes, if the use of abstract classes to buffer can be implemented in the abstract class, and then a1,a2,a3 on-demand overlay methods in the abstract class to achieve the least impact.


This article from "Insist on learning" blog, declined reprint!

Java Basics-Inheritance, abstract classes, interfaces

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.