Question: Create a program that tests the class Merlin described in the previous exercise. Use the toString method to verify that a unique instance has been

Create a program that tests the class Merlin described in the previous exercise. Use the toString method to verify that a unique instance has been created.


Previous exercise.

Sometimes we would like a class that has just a single unique instance. Create a class Merlin that has one attribute, theWizard, which is static and of type Merlin. The class has only one constructor and two methods, as follows:

  • Merlin—a private constructor. Only this class can invoke this constructor; no other class or program can create an instance of Merlin.
  • summon—a static method that returns theWizard if it is not null; if theWizard is null, this method creates an instance of Merlin using the private constructor and assigns it to theWizard before returning it.
  • consult—a non-static method that returns the string "Pull the sword from the stone".

Step by Step Solution

3.43 Rating (166 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public class MerlinTester param args the command line arguments public static void mai... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java An Introduction to Problem Solving and Progra Questions!