Dark Horse programmer--abstract

Source: Internet
Author: User
Tags define abstract

-------<a href= "http://www.itheima.com" target= "blank" >android training </a> <a href= "/http/ Www.itheima.com "target=" blank ">java training </a>, look forward to communicating with you! ----------

I. The definition of abstraction

Abstraction is the extraction of common and essential content from many things.

For example: Wolves and dogs are all canine subjects, and the canine family is the abstract concept.

Second, abstract class

In Java, a method without a method body can be defined, and the concrete implementation of the method is done by the subclass, which is called an abstract method, and the class containing the abstract method is an abstract class.

The origin of the abstract class:

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, no

A method that has a functional body is called an abstract method.

For 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.

Three, the characteristics of abstract class

1. Abstract classes and abstract methods must be decorated with the abstract keyword.

2, abstract method only method declaration, there is no method body, defined in the abstract class.

Format: Modifier abstract return value type function name (parameter list);

3, abstract class can not be instantiated, that is, you can not create objects with new. The reasons are as follows:

Abstract class is the concrete thing extracted, itself is not specific, there is no corresponding instance. For example: The canine family is an abstract concept that really exists in wolves and dogs.

and abstract classes do not make sense to invoke an abstract method even if an object is created.

4, the abstract class is instantiated through its subclasses, and the subclass needs to overwrite all abstract methods in the abstract class before the object can be created, otherwise the subclass is an abstract class.

Note: Abstract classes can have non-abstract methods.

Iv. the difference between abstract class and general class

1, abstract class and general class is not too big difference. How to describe things, or how to describe things. However, there are some parts of the method that do not know the specific content. These are not accurate

The function of the object, which needs to be clarified, but cannot define the subject. Represented by an abstract method.

2, abstract analogy general class more than an abstract function. is to define an abstract method in a class.

3, abstract class can not be instantiated.

4, abstract class Although can not create objects, but there are constructors. For subclasses to instantiate calls.

Note: 1. The function that is modified by the abstract cannot be modified by private, final, static.

Reason:

Final: A class that is final decorated cannot have subclasses. The class that is modified by the abstract must be a parent class.

Private: Abstract methods in the abstract class, not known by the class, can not be replicated.

And the abstract approach is that it needs to be replicated.

Static: If static can modify the abstract method, then even the object is saved, the direct class name is called.

But abstract methods do not make sense to run.

2, abstraction has a special place: Abstract classes can not define abstract methods. This can be done without being instantiated or used for module design.

Dark Horse programmer--abstract

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.