Some java often test knowledge

A, static role

  static modifier is used to modify member variables (static variables / class variables).

  modified static members are shared by all objects .

  static precedence over the object exists.

  static members can be modified by the class name. static member access.

  Note: 1. Static methods can access only static members, non-static method can access static members and can access non-static members.

     2. A static method can not be used this / super keyword.

    3. The main function is static.

Two, final role

  for modifying final class, class attributes, class methods.

  final class can not be inherited modified, the modified class attributes, class methods can not be covered.

  final modified class attribute can not be re-assignment (for constant modifications)

 

Three differences, overload (overloading) and override (rewrite) of

overload (overloading) override (rewrite)
Parameter type, the number, not the same as the order of at least one Method name, arguments, return values ​​for the same
Only different return values ​​for methods can not be overloaded Subclass method can not be reduced access to the parent class method
It is present between the sub-grade and parent class and Subclass method can not throw more exceptions than the parent class
Can not access, return type, exceptions thrown overloaded Present in the parent class and subclass between
Exception type and number of methods will not affect overloaded The method of the parent class is defined as the final can not be overridden
  Is rewritten / coverage in a subclass method, the type of the parent class is not private

  override is polymorphism between child and parent class reflected, overload is the same a polymorphism embodied.

  Compile-time polymorphism achieved by overloading, the runtime implemented by overriding polymorphic (Method coverage).

  java does not support operator overloading.

  

Fourth, the difference between the combination and inheritance

  1. What is inherited

    Inheritance is the subclass inherits behavior characteristics of the parent class is a subclass object (instance) instance fields and methods having a parent class or subclass inherits the parent class, subclass that have the same parent class behavior. In java implementation inheritance by extends. All classes default inherit java.lang.Object subclass. Inheritance is the is-a relationship.

  2. What is the combination

    Generating composition is more complex with new features i.e. encapsulated by combining existing objects. Combination is has-a relationship.

  3. The combination of inherited differences and connections

 

inherit combination
Internal detail visible subclass parent class, which belongs to the code "white cassette" reuse. Between the internal details of the object is not visible, its code are "black cartridge" reuse.
Inheritance in the encoding process to assign specific parent class, its relations at compile clear Relations combination are generally determined at runtime
is-a relationship has-a relationship

 

  4. inherit advantages and disadvantages

    Advantages: support the expansion achieved by inheriting the parent class, but will make the system more complex structure

        Easy to modify the code multiplexed

    Disadvantages: white box reuse the code, the parent class implementation details exposed to subclass break encapsulation

       When the parent class implementation code changes may make the subclass also had to modify, increase maintenance difficulty.

       Subclass lack of independence depends on the parent class, highly coupled

       Does not support dynamic expansion, it was decided at compile the parent class

  The advantages and disadvantages of the combined

    Advantages: Code multiplexing black box, comprising internal object is not visible outside the implementation details, the package is good.

       Loose coupling between the whole class and the local class, independently of each other.

       Extended Support

       Each class focuses only on one task

       Supports extending, combinations of different types can be selected according to the specific target objects at run time (ratio scalability inherited)

    Disadvantages: When you create a whole class of objects, all you need to create a local class object. Cause a lot of system objects.

 

Five, Java initialization sequence (descending order of priority)

  1. Static variables (objects) in preference to non-static variables (objects), the static variable is initialized only once, non-static variables can be initialized multiple times.

  2. The parent preference to subclasses.

  3. Press the member variable initialization sequence defined

  父类静态变量——>父类静态代码块——>子类静态变量——>子类静态代码快——>父类非静态变量——>父类非静态代码块——>父类构造函数——>子类非静态变量——>子类非静态代码块——>子类构造函数

  静态代码块一定在main()方法执行前执行(与顺序无关)

六、HTTP与HTTPS的区别

  HTTP HTTPS
安全性 连接简单,是无状态的 安全的超文本传输协议,比HTTP更加安全
证书 免费 需要申请CA证书,CA证书免费的少
传输是否加密 明文传输 SSL加密传输
端口 80 43

七、产生死锁的主要原因和条件

  1.产生死锁的主要原因

     系统资源不足

    进程运行推进的顺序不合适

    资源分配不当

  2.产生死锁的四个条件

      互斥条件:一个资源只能被一个进程使用

    请求与保持条件:一个进程因请求阻塞时,获得的资源保持不变

    剥夺条件:进程已获得的资源,在未使用完之前,不会强行剥夺

    循环等待条件:若干进程之间形成一种头尾相接的循环等待资源

 

 

Guess you like

Origin www.cnblogs.com/shuo2018/p/11564198.html