Transferred from: http://blog.csdn.net/Mr_KkTian/article/details/70226561
1. Introduction
When you construct an instance of a class, you invoke the constructor of all the parent classes along the inheritance chain. When you construct an object of a subclass, the subclass constructor method first calls the constructor of its parent class before completing its own task. If the parent class inherits from another class, the parent class construction method will then call its own constructor of the parent class before completing its own task. This process continues until the last constructed method along the inheritance architecture is called.
2. Example
Public classFacultyextendsemployee{ PublicFaculty () {System.out.println ("(3) performs Faculty ' s tasks") ; } Public Static voidMain (string[] args) {Faculty FAC=NewFaculty (); }}classEmployeeextendsPerson { PublicEmployee () {System.out.println ("(2) performs Employee ' s tasks"); }}classPerson { PublicPerson () {System.out.println ("(1) performs person ' s tasks"); }}
Operation Result:
(1) Performs person ' s tasks
(2) Performs Employee ' s tasks
(3) Performs Faculty ' s tasks
Java's construction method chain