Java Knowledge Point Summary (9)

Source: Internet
Author: User

Abstract

In the object-oriented realm, abstract classes are primarily used for type concealment, which is the use of abstract types for programming, but concrete types can be used at runtime.

Using abstract concepts, you can create an extensible architecture and optimize your programs in your development projects.

Abstract classes, abstract methods, are design-level concepts in the software development process. In other words, designers will design abstract classes, abstract methods, programmers are to inherit these abstract classes and override the abstract method, to achieve specific functions.

The concept of abstract methods

In some cases, the class cannot (or does not necessarily) provide a concrete implementation of the method, which can be declared as an abstract method;

The method in which there is no method body in a class is an abstract method;

Classes that contain abstract methods must be abstract classes.

Using the keyword abstract to declare an abstraction method, general syntax:

Access rights abstract return value type method name (parameter list);

For example: Public abstract void Draw ();

Abstract class

The concept of abstract classes

If a class does not contain enough information to depict a specific object, such a class is an abstract class.

Classes that are decorated with abstract are abstract classes. If a class contains an abstract method, the class must be defined as an abstract class. Abstract classes, however, do not necessarily have abstract methods.

Classes that are decorated with abstract are abstract classes. If a class contains an abstract method, the class must be defined as an abstract class.

Abstract classes can have member properties and non-abstract member methods.

Abstract classes cannot be instantiated, but they can have constructors.

An abstract class can only be used as a base class, representing an inheritance relationship. A non-abstract class that inherits an abstract class must implement all of its abstract methods, and the parameters and return values of the implementation method are the same as in the abstract class. Otherwise, the class must also be declared as an abstract class.

Abstract classes are defined using the keyword abstraction, general syntax:

[Access rights] abstract class class name {member List}

For example: Public abstract class Shapes {

public abstract void Draw ();}

Considerations for Abstract Classes

Abstract classes can have a construction method, but not directly instantiated, can only be used to inherit;

Derived subclasses of an abstract class should provide a concrete implementation of all of its abstract methods, and if the derived subclass of the abstract class does not implement all of the abstract methods, the derived subclass is still an abstract class and can only be used for inheritance, not instantiation;

Abstract classes can also contain non-abstract methods, when overriding non-abstract methods in subclasses, the return value and parameters must be consistent with the parent class;

Construction methods and static methods cannot be decorated as abstract.

Java Knowledge Point Summary (9)

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.