About Abstract methods and classes

Source: Internet
Author: User

This piece of writing is reprinted from the following URL:

Http://download.oracle.com/javase/tutorial/java/IandI/abstract.html

Just for the use of Self Learning.

 

AnAbstract classIs a class that is declaredabstract-It may or may not include abstract methods.

AnAbstract MethodIs a method that is declared without an implementation (without braces, and followed by a semicolon)

If a class includes des abstract methods, the class itselfMustBe declaredabstract

When an abstract class is subclassed, The subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, the subclass must also be declaredabstract.

Note:All of the methods inInterfaceAreImplicitlyAbstract, soabstractModifier is not used with interface methods (it cocould be-it's just not necessary ).

Unlike interfaces, abstract classes can contain fields that are notstaticAndfinal, And they can contain implemented methods. Such abstract classes are similar to interfaces, doesn't that they provide a partial implementation, leaving
It To subclasses to complete the implementation. If an abstract class containsOnlyAbstract method declarations, it shoshould be declared as an interface instead.

By comparison, abstract classes are most commonly subclassed to share pieces of implementation. A single abstract class is subclassed by similar classes that have a lot in common (the implemented parts of the abstract class), but also have some differences
(The abstract methods ).

An abstract class may havestaticFields andstaticMethods. You can use these static members with a class reference-for example,
AbstractClass.staticMethod()-As you woshould with any other 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.