Java abstract class

Source: Internet
Author: User

Abstract definition:

Abstraction is the extraction of common and essential content from many things.

For example: Wolves and dogs are all canine subjects, and the canine family is the abstract concept.

Abstract class:

In Java, a method without a method body can be defined, and the concrete implementation of the method is done by the subclass, which is called an abstract method, and the class containing the abstract method is an abstract class.

The origin of the abstract method:

Many objects have the same function, but the specific content of the function is different, then in the extraction process, only the function definition is extracted, not the functional body, then only the function declaration, the method without functional body is called abstract method.

Characteristics of abstract Classes

Abstract classes and abstract methods must be decorated with the abstract keyword.

Abstract methods have only method declarations, no method bodies, and are defined in abstract classes.

Format: Modifier abstract return value type function name (parameter list);

Abstract classes cannot be instantiated, that is, you cannot create objects with new. The reasons are as follows:

Abstract class is the concrete thing extracted, itself is not specific, there is no corresponding instance. For example: The canine family is an abstract concept that really exists in wolves and dogs.

and abstract classes do not make sense to invoke an abstract method even if an object is created. Job coordinates www.zhizuobiao.com

An abstract class is instantiated by its subclasses, and the subclass needs to overwrite all abstract methods in the abstract class before the object can be created, or the subclass is an abstract class.

Precautions:

Abstract classes do not necessarily contain abstract methods, but classes that contain abstract methods must be declared as abstract classes

If a class is defined as an abstract class, the class cannot create an object

Protecting data in an abstract class

Abstract classes are primarily inherited by other classes and implement their abstract methods

Abstract classes are usually abstractions of similar classes

Similar classes: Classes that have the same properties, different methods

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.