Question: Question 1 Write a full explanation (in a word file) for the following code showing the static and non-static members, how they are called in





Question 1 Write a full explanation (in a word file) for the following code showing the static and non-static members, how they are called in the Driver class Employee Test, give other values instead of the current and attach a screenshot of your code and output with the explanation file. I // Fig. 8.12: Employee.java 2 // static variable used to maintain a count of the number of 3 // Employee objects in memory. 4 5 public class Employee 7 private static int count - 0; // number of Employees created 8 private String firstName; 9 private String lastName; 10 // initialize Employee, add 1 to static count and 12 // output String indicating that constructor was called 13 public Employee(String firstName, String lastName) 14 { 15 this.firstName = firstName; 16 this.lastName = lastName; 17 18 ++count; // increment static count of employees 19 System.out.printf("Employee constructor: %s %s; count = %d %n", firstName, lastName, count); 21 } 11 20 22 Fig. 8.12 static variable used to maintain a count of the number of Employee objects in memory. (Part 1 of 2.) 23 24 27 28 30 31 32 // get first name public String getFirstName() 25 { 26 return firstName: ) 29 // get last name public String getLastName() { return lastName; 33 } 34 35 W/ static method to get static count value 36 public static int getCount() { return count; } 40 } // end class Employee 37 38 39 Fig. 8.12 | static variable used to maintain a count of the number of Employee objects in memory. (Part 2 of 2.) 1 // Fig. 8.13: Employee Test.java 2 1/ static member demonstration. 3 4 public class EmployeeTest 5 { public static void main(String[] args) 7 8 // show that count is O before creating Employees 9 System.out.printf("Employees before instantiation: %d%n". 10 Employee.getCount); 12 // create two Employees; count should be 2 13 Employee el = new Employee("Susan", "Baker"); 14 Employee e2 = new Employee ("Bob", "Blue"); 15 16 1/ show that count is 2 after creating two Employees 17 System.out.printf("%Employees after instantiation:%n"): 18 System.out.printf("via el.getCount(): %d%n", el.getCount(); 19 System.out.printf("via e2.getCount(): %d%n", e2.getCount(); 20 System.out.printf("via Employee.getCount: %d %n", 21 Employee.getCount); 22 Fig. 8.13 | static member demonstration. (Part 1 of 2.) 23 // get names of Employees 24 System.out.printf("%Employee 1: %s %s%Employee 2: %s %s%n", 25 el.getFirstName(), el.getLastName(), 26 e2.getFirstName(), e.getLastName()); 27 } 28 } // end class EmployeeTest Employees before instantiation: 0 Employee constructor: Susan Baker; count = 1 Employee constructor: Bob Blue; count 2 Employees after instantiation: via el.getCount(): 2 via e2.getCount(): 2 via Employee.getCount(): 2 Employee 1: Susan Baker Employee 2: Bob Blue Fig. 8.13 static member demonstration. (Part 2 of 2.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
