Overview of the Java final static abstract keyword

  • 2020-05-09 18:42:30
  • OfStack

1, abstract class :abstract

1. Any class that has one or more abstract methods must be declared as an abstract class using abstract;

2. Abstract classes can have concrete implementation methods;

3, there can be no abstract methods in the abstract class;

4. An abstract method in an abstract class must be implemented by its subclass, which continues to be an abstract class if it is not implemented

5. The abstract class cannot be instantiated, but the concrete implementation method in the abstract parent class can be called by the subclass instance pointed by the abstract parent class; Usually as a default behavior;

6. To use the method in the abstract class, one subclass must inherit from the abstract class and realize the abstract method in the abstract class, which is called by the instance of the subclass;

2, the interface: interface

1. There can be member variables in the interface, and the member variables in the interface must be defined and initialized;

2. The member method in the interface can only be a method prototype, not a method body;

3. The member variables and methods of the interface can only be public(or not written by default), and the effect of 1 is public

4. The class that implements the interface must implement all the methods in the interface (the implementation of the parent class is also included; 1).

3. Keywords :final

1. Can be used to modify: member variables, non-abstract classes (which cannot occur at the same time as abstract), non-abstract member methods, and method parameters

2. final method: cannot be overridden by subclass methods, but can be inherited;

3,final class: indicates that this class cannot be inherited and there is no subclass; Methods in the final class also cannot be inherited.

4. final variable: represents a constant, which can only be assigned once and cannot be modified after being assigned.

5,final cannot be used to modify constructors;

6,final parameter: only this parameter can be used, and the value of this parameter cannot be modified;

4. Keywords :static

1. You can modify member variables and methods, but you cannot modify classes and constructors;

2, the member variables and member methods modified by static are independent of any object of the class. That is, it is not dependent on a specific instance of the class and is Shared by all instances of the class

3. The static variable and static method 1 are normally accessed directly by the class name, but can also be accessed by an instance of the class (this is not recommended).

4, the static variable and static method are also suitable for the java access modifier. The static variable and static method, which are modified with public, can be accessed directly from the class name anywhere, but the static variable and static method, which are modified with private, can only be accessed from the declared class method and static block, but cannot be accessed with this, because this is a non-static variable.

5,static and final are used together

1,static final is used to modify member variables and member methods, which can be simply understood as "global constants"!

2. For variables, the value of 1 cannot be modified and can be accessed through the class name.

3. For methods, it means that they are not overridden and can be accessed directly by the class name.

6. Why can't you add abstract and static before one method?

static is static, which is what is determined at compile time, and certainly not abstract (dynamic), which is what is determined at run time

The above content is this site to introduce you Java final static abstract keyword, I hope to help you!


Related articles: