Java abstract keyword

Source: Internet
Author: User

Abstract class:

1. Syntax Definition: Abstract class of money using the abstract keyword decoration, the class is abstract

2. Usage scenarios:

      • In some cases, a parent class simply knows how its subclasses should be, but does not know exactly how these subclasses implement these methods
      • Abstract an abstract class from multiple classes with the same characteristics, using this abstract class as a template for subclasses, thus avoiding the arbitrariness of sub-class design

3. Function:

      • Restriction subclasses must implement some methods, but do not care about implementation details

4. Usage rules:

      • Abstract class definition
      • Abstract defines abstractions, only declarations, and does not need to implement
      • Classes that contain abstract methods are abstract classes
      • An abstract class can contain ordinary methods, or there can be no abstract method

5. code example:

1  Public Abstract classtelphone{2      Public Abstract voidCall ();3      Public Abstract voidmessage ();4 }5  Public classCellPhoneextendstelphone{6 @Override7      Public voidCall () {8     9     }Ten @Override One      Public voidmessage () { A      -     } - } the  Public classSmartPhoneextendstelphone{ - @Override -      Public voidCall () { -      +     } - @Override +      Public voidmessage () { A      at     } - } -  Public classtest{ -      Public Static voidMain (string[] args) { -Telphone TP1 =NewCellPhone (); - Tp1.call (); in tp1.message (); -Telphone TP2 =NewSmartPhone (); to Tp2.call (); + tp2.message (); -     } the}
abstract Keyword

Java abstract keyword

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.