Java Essentials Note (7)----three modifiers

Source: Internet
Author: User
Tags instance method modifier modifiers

  1. Abstract Abstraction
      1. method
        1. Abstract method: The method of an abstract modification, which is only declared without the implementation of the method (not even {}).
        2. syntax: modifier Returns a value type method name (formal parameter list);
        3. Note: Abstract methods must be defined in an abstract class.
      2. class
        1. abstract class: by AB Stract decorated class, cannot instantiate (create object).
        2. syntax: modifier class class name [Inheritance relationship]{}
        3. Note:
          1. abstract class does not create objects; but can declare references (forced polymorphism).
          2. Abstract classes can have abstract methods or non-abstract methods.

          The benefit of the abstract class: forcing polymorphism.

  2. static statics,
    1. Attribute/instance Variable
      1. Syntax: Within the class, the static data type variable name outside the method;
      2. Concept: A class variable/static variable, which is a static modified property/instance variable that is shared by all objects of that class (object-independent).
      3. Use: Class name. property name
    2. Method/instance method
      1. syntax: access modifier static return value type method name ( Formal parameter list {

        //method implementation part

        }

      2. Concept: Class method/static method, refers to the static modified method, is shared by all objects of the class (Object-independent).
      3. use: Class name. Method name (argument);//Suggestion
      4. Note: This and super are not allowed in
      5. The method of span style= "font-size:12pt" >static modification can be inherited, but only by static method, but not polymorphic (see below);
    3. static code block
      1. initial code block: a block of code defined outside of a class, as a method. The
  3. final final
    1. variable (instance variable + local variable +static variable)
         The
      1. final modified variable is the final variable and can only be assigned 1 times without modification (constant).  
      2. Note: The
        1. final decorated instance variable will no longer be assigned a default value;
        2. can assign initial values in the Declaration/initialization code block/constructor method;
        3. If you use the constructor method To assign the initial value to the final attribute, it is necessary to ensure that the initial value is assigned to all constructs. The
        4. final decorated class variable will no longer be assigned a default value, and the initial values can be assigned to the declaration/static code block. When
        5. final modifies a variable of a reference type, the value representing the reference itself is not allowed to be modified (the address value is not allowed to change).

     

    1. method The
      1. final decoration method is the final method and cannot be overridden. The
    2. class
      1. final decorated class is the final class and cannot be inherited.
      2. If a class is final, all methods in the class are final.
  4. Expansion and Promotion:
    1. Static,final and abstract are not able to modify the construction method
    2. Class loading
      1. Concept: When the JVM uses a class for the 1th time, it first finds the corresponding. class file from the Classpath, reads all the contents of the file (Properties/Methods/class name/package structure/construction/static ...), and saves the process, called class loading.
      2. Class loading is performed only 1 times in the same JVM.
      3. Class load time: 1th time a class is used
        1. Create objects of this class
        2. Use static members of this class (static variable/static method)
        3. Create child class objects or use static members of subclasses
          1. Recursively loads the parent class Class 1 times
          2. Subclass classes Loaded 1 times
          3. Allocate space All instance variables assign default values
          4. Recursive creation of parent class objects
          5. Initializes this class of properties and initial code blocks to execute as defined
          6. Call this class constructor method

Java Essentials Note (7)----three modifiers

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.