How to distinguish between class abstract class interface subclass test class

This article is mainly based on the java language. I also wrote this article after I have a certain understanding of these pieces of content. I hope that the big guys will criticize it!

1. Popular language understanding:

Class: This is the most basic. A class is often a .java; because of the class, we can write some of our methods in it, and we can create objects based on this class, so what methods each object needs I can use any method in this class instead of writing a method. This is also the power of object-oriented.

Abstract class: eating is a function that an animal has, but we can’t be specific about what each animal eats, but we know that they all have a function of eating, so we define an abstract class, then let each concrete The class inherits this abstract class, but we can write concretely what we eat. Some people may wonder, since it still needs to be written specifically, why do we need to create a separate class! My understanding now is that when the code is more cumbersome, we can clearly see the relationship between the class and the class by inheriting the abstract class; at the same time, the most important point is that we also save a lot of repetitive code.

Interface: Functionally speaking, interfaces and abstract classes are very similar, but their uses are really different. For example, we can write a notebook in java, which has all the functions of a computer, and then create an object: Xiao Wang’s computer, but this Sometimes I need a USB flash drive. We sometimes use this USB flash drive. This is actually not a function of all computers. Because not all computers need a USB flash drive, so we can use an interface to implement a USB flash drive. Which computer needs us You can implement

Subcategories: As mentioned earlier, animal categories have many commonalities, so everyone that is called an animal can inherit this category, then cats, dogs... these can be called subcategories of animals.

Test class: generally refers to our public static void main(String[] args) {

Internal class: We defined an animal class or a human or a computer. Take the computer as an example. The cpu and hard disk in the computer are all regarded as a class. Then we can call the cpu an internal class of the computer. The internal category breakdown also includes:

1. Member inner class: Most of the design of this class does not want to be directly accessed by the outside world, so the definition of the inner class should be privatized. After privatization, define an external call method, and create and call the inner class object in the method.

2. Local inner class: the class defined in the method

3. Anonymous inner class (belonging to a local inner class): new class name () {override method}

Next, there will be instructions on specific grammatical rules

Guess you like

Origin blog.csdn.net/qq_34159161/article/details/105054121