Package - block --private-- inheritance - permissions modifier - rewrite --super

1.package (packages):

When the java compiler at compile time, that will be generated class file storage directory according to the package.

After the package directory:

 

After the deposit of:

2.block (Block) - '{} 

  • Is a scope
  • Divided into two types: a write method (ordinary or partial statement block code block), when the execution time of the method call (. Building blocks before the code executed before the constructor code, because the compiler when compiling automatically configured to compile the code block before the constructor code ) 
  •                   B. Write outer class method (building blocks), the execution time of an object when it is created.
  • written in the outer static {} class methods, static blocks called, execution time is the class loading. static blocks may be placed anywhere in the class, the class may have a plurality of static blocks. When the class is loaded for the first time, each of the static block may be performed in the order of static blocks, and only once.

 

 

 

 The order of execution: a static block building block --main-- - Constructor

 

 

 

3.private Keywords:

Objective: To address security risks such as passing a negative number of age - private, this can only be used in the current class, the external class can not be used - once private property, it is necessary to set and access with the use setter getter, public method

Benefits: a improve code reusability b improve security code.

 

4. Inheritance

Objective: easy to use, once the subclass inherits the parent class can use all the contents of the parent class, a parent can have many subclasses, but only a subclass of a parent class.

Cons: not easy to post-maintenance

5. permissions modifier

 

  • default keyword default, do not write omitted
  • Modified class can only be public | default
  • Protected content can be modified using the method: 1 with 2 different subclasses package under the package to use, and must be inherited by the child parent relationship between use can

6. Rewrite

Detection method overrides manner: triangle 2. @ Override annotation will be forced upwardly check override method 1. The left

note:

  • Modified private methods can not be overridden
  • The modified final keyword method can not be overridden
  • 被static修饰的方法不能被重写
  • 如果子类中有与父类中的某个静态方法同名的时候,那这个方法也要为static修饰的

 

 

7.super关键字:(指代父类对象)

  • 调用父类的构造器——super()若没显示定义,默认首行调用super()父类空构造,建议模板类至少存在一个空构造;
  • super()必须在首行,必须放在子类的构造器里
  • 区分子父类同名:例如子父类都有变量a,在子类调用父类的a需要super.a进行调用。

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/lingxi2b2/p/11937737.html