Create a program that tests the class Merlin described in the previous exercise. Use the toString method
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 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".
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Question Posted: