abstract Java keyword's, final, static usage

abstract : abstract i.e., may be modified based process;

  Modified class: When there is a way to abstract method, the class is an abstract class, abstract class can not be new, it is an incomplete class.

  Modification method: This method is abstract, that can only be defined method, there is no implementation of the method.

final: That final can be modified classes, attributes, methods;

  Modified class: This class can not be inherited

  Modification of property: This property value can not be changed

  Modification method: This method is the final method can not be overridden (covered)

  a.final, finally, finalize the difference?

    final declaration for the class, attributes, methods; represents immutable properties, the method can not be overwritten, the class can not be inherited.

    Exception handling is finally part of the statement, representation is always executed.

    finalize is a method object, and when the garbage collector will call the execution method of the object, for recovery of other resources when garbage collection.

static: static modifier for modification of members and member functions can be invoked directly by the class name.

  Modification of property: This property is static properties (static variables | class variables)

  Modification method: This method is a static method (class method)

    Note: Non-static method static method can not be called directly; member method static method can be called directly

  Modified Block: block of code will be executed when the class is loaded, and only once (static code block)

  Features:

    And loading with class loading, prior static, then there object generator;

    All objects are shared;

    It can be directly invoked the name of the class;

    Static variables can not be called directly member variables;

Interview Question: Why can not abstract, final, static classes coexist with private?

  abstract modified class must be inherited, modified methods should be rewritten;

  final modification classes, properties, methods can not be changed, and therefore the modified method can not be rewritten;

  private class can only be modified inside the class, the modified properties, methods in this class can only be called internally, overridden methods can not access these methods and properties;

  static modification of the method is static, the class can be invoked, but the abstract modification method is abstract, there is no way the body can not be called directly, needs to be rewritten to use the abstract methods through inheritance or interface implementation class.

Guess you like

Origin www.cnblogs.com/HuiH/p/11652732.html