What is abstract class

Source: Internet
Author: User
Tags abstract definition class definition function definition

1. Abstract class definition: Abstract is from a number of things will be common, the essence of the content extracted.

2. The origin of the abstract method: multiple objects have the same function, but the specific content of the function is different, then in the extraction process, only the function definition is extracted, not the function body, then only the function declaration, the method without the function body is called abstract method.

2.1 Example: Wolves and dogs have a way of yelling, but the content of the Roar is different. So the abstract canine has a roaring function, but it does not specify the details of the Roar.

3. Characteristics of abstract classes:

3.1: Abstract methods can only be defined in abstract classes, abstract methods and abstract classes must be decorated with the keyword abstract.

3.1: Abstract class values define method declarations only, and do not define feature topics (that is, the implementation of methods).

3.2: Abstract class can not be created object.

3.3; Abstract classes only subclasses inherit methods from the parent class and override all of the abstract methods in them. This subclass is not an abstract class, as long as it is not a rewrite of all the abstract methods, then this subclass is abstract class

4. Note the point:

4.1: Whether there are constructors in the abstract class. There, used to initialize the subclass object.

4.2: Whether a non-abstract method can be defined in an abstract class. OK

4.3: Abstract keyword abstraction and which can not coexist. Final, private, static

4.4:: Abstract methods can not be defined in an abstract class. OK. The abstract method is intended only to keep the class from creating objects.

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.