Fields
Inheritance gives a child fields of the parent class. * The parent class's fields are passed down to the child; the child inherits them from the parent class. * This is one of the main reasons to use inheritance, as it keeps us from duplicating code in other classes.
We can imagine our Employee extends Person class diagram looking like

The Employee class has all the Person fields, but the fields and methods only exist in Person.
Drill¶
Inheritance/com.example.inheritance.drills.Employee* Add a no-arg constructor toEmployee. * Add a constructor toEmployeewith parameters forfirstName,lastName,age,title, andsalary. * Set the fieldsfirstName,lastName, andagethe same way astitleandsalary- using the.operator. * Add a method toEmployeecalledpublic String getInfo()* Return aStringcontaining the object's information in the formatfirstName lastName age title salary.
Inheritance/com.example.inheritance.drills.EmployeeApp
- Follow the instructions to create
PersonandEmployeeinstances, and call methods for each.- (Solution: Employee2.java, EmployeeApp.java)