Java Abstract class)

Source: Internet
Author: User

Java Abstract class: 2008.10.29

  • Abstract classes are classes that cannot be converted into objects.
  • When a class is declared as an abstract class, you must add the modifier Abstract
  • An abstract class can contain anything that a general class can contain.
  • Abstract classes can also contain abstract methods. This method can only be declared and not implemented (conventional classes cannot contain abstract methods)
  • If an abstract class does not have any abstract methods, it is more appropriate to use interfaces.
  • Abstract classes are used for inheritance. They exist for the following reasons:
    • Abstract classes are high-level summaries of classes.
    • Abstract classes can include the public attributes and public behaviors shared by all their subclasses.
    • When an instance is generated, the user is forced to generate more specific instances to ensure code security.

Abstract Method

  • Abstract methods are added with abstract keywords during method declaration.
  • Abstract methods are declared and not implemented.
  • Only abstract classes can have abstract methods.
  • If a subclass of an abstract class is not an abstract class, it must overwrite all abstract methods in the parent 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.