1. Initialization Order of inheritance:
Parent class, parent class, properties in the initialization object of the parent class---the constructor method of the property, child class, subclass
If there is a constructor: Execute the property first, then the construction method
If the Name property is not assigned to the constructor, the value of name is the value assigned to the Class property
package COM.WANGCF; // parent class public class Animal { public String name= "Initialization of properties" ; public int age; public void eat () {System.out.println ( "animals can Eat" public Animal () {Name = "Construction method The initialization of "; System.out.println ( "The construction method of the parent class performed the"
package COM.WANGCF; // subclass public class Bridge extends animal{ public String name=" sub-class Property "; public Bridge () {System.out.println ( span> "The constructor of the subclass" ); }}
Package COM.WANGCF; // Test Class Public class Test { publicstaticvoid main (string[] args) { Bridge bri= New Bridge (); Test initialization Sequence System.out.println (bri.name); The assignment method of the test attribute is System.out.println ("============="); Animal ani=new Animal (); System.out.println ("Output value:" +ani.name); Test the assignment of a property }}
2.fianl
Class can be decorated, the class cannot be inherited
You can modify the method, the method cannot be overridden
Properties can be modified: the properties of the class are not implicitly initialized, that is, the final int a=1 must be assigned, correct; fianl int A; error
or assign a value in the constructor method
Choose one of these two ways
Variable can be modified: it can only be assigned once, then it is constant.
Inheritance of Java