Question: on A) The following code has a compiler error in which line do you see the error, and what causes the program to generate such

on A) The following code has a compiler error in which line do you see the error, and what causes the program to generate such an error? 3 public class My Factory { 4 private String name; 5 private int id; 6 private static int counter 0; 7 private MyFactory(String name) { 8 this.name = name; 9 this.id counter; 10 } 11 public String getName(){ 12 return this.name; 13 } 14 public int getId({ 15 return this.id; 16 } 17 public static String getInfo({ 18 return + counter + " " + name; 19 } 20} B) Assume that we were able to correct the error in this code. Write a static factory method called getinstance for this class which gets a string for the name as its input parameter. The counter variable should be incremented before the new instance is created so that each new instance gets a new id. Write an accessor method by which a dient can get access to the counter variable, H11 14 15 16 17 18 19 20 } public int getId({ return this.id; } public static String getInfo({ return"" + counter + + name: } B) Assume that we were able to correct the error in this code. Write a static factory method called getinstance for this dass which gets a string for the name as its input parameter. The counter variable should be incremented before the new instance is created so that each new instance gets a new id. Write an accessor method by which a client can get access to the counter variable. Da client creates an instance of MyFactory and names it mft, and then prints the object by System.out.println(m) what will be printed? Explain, by writing code, how you can change this output so that the name followed by a space followed by the id of mf is printed by System.out.println( mt)
Step by Step Solution
There are 3 Steps involved in it
A Compiler Errors Line 3 public class My Factory Error The class name contains a space It should be ... View full answer
Get step-by-step solutions from verified subject matter experts
