Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE answer whatever you can.. and as soon as possible! JAVA This question has a parts Al The following code has a compiler error. In

PLEASE answer whatever you can.. and as soon as possible! JAVA

image text in transcribed

This question has a parts Al The following code has a compiler error. In which inc 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 7 14 public int getId({ 15 return this. id; 16 } 17 public static String getInfo{ 18 return"" + counter + " " + name; 19 7 20] Bassume that we were able to correct the error in this code. Write a static factory method called gedinstance() tor this class, which gets a string for the name as its input parameter. The counter variable should be incremented betore the new instance is created so that cach new instance gets a new ist Gwrite an accessor method by which a client can get access to the counter variable. Dj If a client creates an instance of MyFactory and names it mi, and then prints the object by System.out.prindhimt, what will be printed? Explain, by writing code, how you can change this output so that the name followed by a space to lowed by the ic of mt' is printed by System.out.printinmal

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions