Java abstract class

Source: Internet
Author: User

Abstract class:

What is an abstract class?

In object-oriented concepts, we know that all objects are depicted through classes , but not in the opposite way. Not all classes are used to depict objects, and if a class does not contain enough information to depict a specific object , such a class is an abstract class.

The abstract concept of design?

Abstract classes are often used to characterize the abstract concepts we derive in the analysis and design of problem areas, and are abstractions of a series of concrete concepts that look different, but are essentially the same .

For example, if we develop a graphical editing software, we will find that there are some specific concepts of circle and triangle in the problem domain, they are different, but they all belong to the concept of shape , the concept of shape does not exist in the problem domain, it is an abstract concept .

Cannot instantiate?

Abstract classes used to characterize abstract concepts cannot be instantiated because abstract concepts have no corresponding specific concepts in the problem domain.

Two kinds of mechanisms for implementing abstract classes in Java: Abstractclass & Interface

At the grammatical level, compare:

Abstract class demo{

abstract void method1 ();

Void method2 (); All member methods may be abstract or non- abstract

}

Interface demo{

Static final int I; The data member must be a static final type

(Abstract) void method1 (); All the member methods are abstact

}

On the programming:

Abstract class: Inheritance relationship, one class can only use one inheritance relationship

Can give method default behavior

Interface: A class can implement multiple interface

Method cannot have default behavior (behaves as code duplication in derived classes, which is not conducive to code maintenance)

The design concept:

Abstract class: Essentially represented as a class, so and inheritance (extends) is a relationship of "isa"

Interface: Just a contract implementation (implements)

http://www.ibm.com/developerworks/cn/java/l-javainterface-abstract/

Java abstract class

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.