White Tour 10

A. Final keyword

  • final modification of variables into constants, constants can not be modified

Note: If the final member variable is modified, then the member variables are not given default values, you must manually initialize

  • The modified final object can not be reassigned
  • The modified final category is the final class, the final class can not be inherited

Note: final and abstract can not coexist, because the abstract class must be inherited only makes sense, and final modification of the final class can not be inherited

  • The modified method can not be overridden by subclasses final

II. Packages and introduction

Keywords: package, import

  • package: represents the current packet belongs to the class
  • import: If another type of package, the package structure of this class will need to import into the current through the class

Note:

1, import demand import can use an asterisk, for example: import java.util *; import system represents util package according to the current class used in the class.
2, without the need to manually import lang package, each class has automatically import the lang language pack

III. Permissions (range) modifier

Concept: visibility for the modification of members
have public protected [default] private
Note: Permission modifier can only be modified members, can not be modified locally

                 public    protected    [default]       private
本类                  √            √            √            √
同包不同类               √            √            √            ×
不同包的子类          √            √            ×            ×
不同包的无关类      √           ×            ×            ×

Range of different usage rule modifiers:
. 1, public: tools, provide external features
2, protected: allowing access to the parent class subclasses of different content packages
3, [default]: subclass allowed access to the parent class content of different packages
4, private: encapsulation properties, singleton

Guess you like

Origin www.cnblogs.com/demonycw/p/11329329.html