[Java Basics] Basic Knowledge Error-prone Collection (1)

On the way of learning, we only remember to learn new knowledge, but ignore that all new knowledge is based on old knowledge; in the process of running hard, we must also remember to look back frequently;

Topic display: 

Parse:

      Abstract means abstract. In java, it is stipulated that only classes or methods can be modified, so attributes (fields) cannot be modified.
(1) The abstract modification class will make this class an abstract class. This class will not be able to generate object instances, but it can be used as the type of object variable declaration (see the example below), that is, the compile-time type. An abstract class is equivalent to a class of semi-finished products, which require subclasses to inherit and override the abstract methods.
(2) The abstract modification method will make this method an abstract method, that is, there is only declaration but no implementation, and subclass inheritance is required to implement (overwrite).

Analysis of the cause of the error:

        Confuse private (privatization) with abstract (abstract);


Parse:

       Let's distinguish the following concepts:

  • ① Construction method: The construction method is used to construct the object of the class. The method name is the same as the class name and has no return value. Generally use the new constructor name () to create objects of this class. In the case of not writing a constructor, there will be a default no-argument constructor. Of course, you can also rewrite and overload the constructor.
  • ② instance method: namely: member method. Simply put, it is a method that can be called through an instance of a class (an object), which is the method we use under normal circumstances.
  • ③ Class method: Simply put, it is a method that can be called directly by the class name, that is, a method modified by the keyword static, which does not need to create an object of the class to call the method.
  • ④ Parent class and super class mean the same thing, just different names. It can also be divided into direct parent class and indirect parent class, which are just different names in different books.

So can an instance method directly call an instance method of a superclass?

        Answer: If the instance method of the superclass is not overridden in the subclass, it can be called directly, but if it is overridden by the subclass, it will be overwritten. At this time, it needs to be called through the super keyword.

Error analysis: unstable foundation;


Parse:

        An abstract class can declare and define a constructor, which is used to initialize the general variables declared inside the abstract class and used by various implementations. Also, even if you don't provide any constructor, the compiler will add a default no-argument constructor to the abstract class, without which your subclass won't compile because the first statement in any constructor implicitly calls super (), the constructor of the default superclass in Java.

In addition, several abstract class-related knowledge points are emphasized (refer to the link below):

Abstract class knowledge points_Nanzhai Lone Crane's Blog-CSDN Blog

Reason for the error: the basics are forgotten;


Parse:

        In Java, parent class constructors cannot be inherited by subclasses, so they cannot be rewritten.
        It's just that when constructing a subclass, the subclass will first call the construction of the parent class in the constructor, and the no-argument construction of the parent class is called by default. If you need constructions with different numbers of parameters, you can write multiple construction methods in the parent class. 

Guess you like

Origin blog.csdn.net/m0_64231944/article/details/128248257