Java abstract class

Source: Internet
Author: User

Java abstract class
The class that uses the keyword abstract declaration is called an abstract class. If a class contains one or more abstract methods, the class must be specified as abstract. An "abstract method", which belongs to an incomplete method, contains only one declaration and no method body.
Chinese name
Java abstract class
Meaning
class using the keyword abstract declaration
Syntax
abstract void f ();
"Abstract Method"
belong to an incomplete method
Abstract syntax The following syntax is used for abstract method declarations: abstract void f (); If you inherit from an abstract class and want to generate an object of a new type, you must provide a method definition for all the abstract methods in the underlying class. If you do not (you can choose not to do so), then the derived class will also be abstract, and the compiler will force us to use the abstract keyword to flag the "abstract" nature of that class. Even if you do not include any abstract methods, you can declare a class as an "abstract class." This ability is useful if a class does not necessarily have any abstract methods, and we want to prohibit all instances of that 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. Abstract classes are often used to characterize the abstract concepts we derive from 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. Abstract classes used to characterize abstract concepts cannot be instantiated because abstract concepts have no corresponding specific concepts in the problem domain. Abstract classes are primarily used for type concealment in the object-oriented realm. We can construct an abstract description of a fixed set of behaviors, but this group of behaviors can have any possible concrete implementation. This abstract description is an abstract class, and any possible concrete implementation of this group is represented by all possible derived classes. The module can manipulate an abstract body. Because the module relies on a fixed abstraction, it can be modified, and the behavior of this module can be extended by deriving from this abstraction. Readers familiar with OCP must know that abstract classes are key in order to achieve a core principle OCP (open-closed Principle) for object-oriented design. Contrast interface syntax definition layer in abstract class mode, the demo can have its own data members, but also can have non-abstract member methods, and in the implementation of interface mode, The demo can only have static data members that cannot be modified (that is, it must be static final, but the data members are not generally defined in interface), and all member methods are abstract. At the programming level, abstract class represents an inheritance relationship in the Java language, and a class can only use one inheritance relationship at a time. However, a class can implementMultiple interface. The design concept level abstract class embodies an inheritance relationship in the Java language, in order to make the inheritance relationship reasonable, there must be an "is a" relationship between the parent class and the derived class, that is, the parent class and the derived class should be the same in nature. For interface, it does not require that the interface and interface definitions be consistent in concept, but only that the contract (function) of the interface definition is implemented.

Java abstract class

Related Article

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.