The initialization order of java parent class variables and subclass variables

Preface

I met a classmate today. He asked me why his code reported an error. I looked at it and found that he had mistaken the initialization sequence of the parent class and subclass variables. I smiled and told him patiently.

1. Parent class static variable and static code block (declared first, execute first)
2. Subclass static variable and static code block
3. Parent class variable and code block
4. Parent class construction method
5. Subclass variable and code Block
6, subclass construction method

Guess you like

Origin blog.csdn.net/qq_44688861/article/details/114362199